English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM offsetLeft Property

HTML DOM Element Object

offsetLeftRead-only property to get the distance from the left outer border of the element to the left inner border of the offsetParent element (in pixels).

The returned value includes:

  • The left position and margin of the element

  • The left padding, scrollbar, and border of the offsetParent element

Note:ThisoffsetParentThe element is the closest parent element except for static.

To return the top position of the element, useoffsetTopProperty.

Syntax:

element.offsetLeft
var myBox = document.getElementById("box");
document.getElementById("result").innerHTML = myBox.offsetLeft;
Test and See‹/›

Browser Compatibility

All browsers fully support the offsetLeft property:

Property
offsetLeftYesYesYesYesYes

Technical Details

Return Value:A number representing the left position of the element, in pixels
DOM Version:CSS Object Model (CSSOM)

More Examples

Return the position of the DIV element:

var myBox = document.getElementById("box");
var x = document.getElementById("result");
x.innerHTML = "offsetLeft: " + myBox.offsetLeft + "<br>offsetTop: " + myBox.offsetTop;
Test and See‹/›

Related References

HTML DOM Reference:offsetHeight property

HTML DOM Reference:offsetWidth property

HTML DOM Reference:offsetTop property

HTML DOM Reference:offsetParent property

HTML DOM Element Object