offsetLeft property

The offsetLeft property contains the element's left offset relative to offsetParent. It contains the distance from offsetParent to the element border.

Syntax

javascriptelement.offsetLeft;

Example

Let's find the offset of an element relative to its own offsetParent:

html<div id="parent" style="position: relative;">
  <div id="elem" style="position: absolute; left: 100px"></div>
</div>
javascriptlet elem = document.querySelector('#elem');
console.log(elem.offsetLeft);

The code execution result:

javascript100

Example

Margins are also included into offset:

html<div id="parent" style="position: relative;">
  <div id="elem" style="position: absolute; left: 100px; margin: 50px"></div>
</div>
javascriptlet elem = document.querySelector('#elem');
console.log(elem.offsetLeft);

The code execution result:

javascript150

See also