THE WORLD'S LARGEST WEB DEVELOPER SITE

Element offsetLeft Property

❮ Element Object

Example

Get the offsetLeft position of a <div> element:

var testDiv = document.getElementById("test");
document.getElementById("demo").innerHTML = testDiv.offsetLeft;
Try it Yourself »

Definition and Usage

The offsetLeft property returns the left position (in pixels) relative to the left side the offsetParent element.

The returned value includes:

  • the left position, and margin of the element
  • the left padding, scrollbar and border of the offsetParent element

Note: The offsetParent element is the nearest ancestor that has a position other than static.

Tip: To return the top position of an element, use the offsetTop property.


Browser Support

Property
offsetLeft Yes 8.0 Yes Yes Yes

Syntax

Return the left offset position:

object.offsetLeft


Technical Details

Default Value: no default value
Return Value: A Number, representing the left position of the element, in pixels
DOM Version: CSSOM

More Examples

Example

Get the position of a a <div> element:

var testDiv = document.getElementById("test");
var demoDiv = document.getElementById("demo");
demoDiv.innerHTML = "offsetLeft: " + testDiv.offsetLeft + "<br>offsetTop: " + testDiv.offsetTop;
Try it Yourself »


❮ Element Object