Easy Tutorial
❮ Prop Area Coords Jsref Obj Regexp ❯

HTML DOM offsetLeft Property

Element Object

Example

Get the left offset of a div element:


Definition and Usage

offsetLeft is a read-only property that returns the offset in pixels of the current element relative to the left boundary of the offsetParent node.

The return value includes:

Note: The offsetParent element is a reference to the nearest positioned ancestor (in terms of containing hierarchy) or the nearest table cell element.

Tip: To get the top offset of an element, use the offsetTop property.


Browser Support

Property Chrome Edge Firefox Safari Opera
offsetLeft Yes Yes Yes Yes Yes

Syntax

element.offsetLeft

Technical Details

| Return Value: | Returns an integer representing the left offset of the element in pixels. | | --- | --- |


More Examples

Example

Get the position of a div element:

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

Element Object

❮ Prop Area Coords Jsref Obj Regexp ❯