# Get the offset position of an element relative to its parent in JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Aug 14, 2020, updated Sep 23, 2021. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-dom-get-the-offset-position-of-an-element-relative-to-its-parent

> Learn how to get the offset position of an element relative to its parent in JavaScript.

To get the offset position of an HTML element relative to its parent, you can use the `offsetLeft` and `offsetTop` properties of the element.

Here is example:

```javascript
const div = document.querySelector('.pizza');

console.log(`Offset Position: (${div.offsetTop}, ${div.offsetLeft})`);
```

The above example prints the top-left coordinates of an element relative to its parent pixels. By default, the top left corner of the element is `(0, 0)`. The `scrollLeft` and `scrollTop` properties are relative to the default coordinate.
