HTML DOM offsetLeft property
Example
Get the left offset of the div element:
var
testDiv
=
document
.
getElementById
(
"
test
"
)
;
document
.
getElementById
(
"
demo
"
)
.
innerHTML
=
testDiv
.
offsetLeft
;
Try it »
Definition and Usage
offsetLeft is a read-only property that returns the offset pixel value of the current element relative to the left boundary of the offsetParent node.
The return value includes:
- The pixel value of the element's left offset, the element's margin
- The left padding, border and scrollbar of the offsetParent element
Note: offsetParent The element is a reference to the nearest (in terms of containment hierarchy) positioned element or nearest element that contains it.
Tip: To get the top offset of the element, use offsetTop attribute.

Browser support
| property | |||||
|---|---|---|---|---|---|
| offsetLeft | Yes | Yes | Yes | Yes | Yes |
Syntax
element.offsetLeft
Technical Details
| Return Value: | Returns an integer representing the left offset of the element, measured in pixels (px). |
|---|
More examples
Example
Get the position of the div element:
var
testDiv
=
document
.
getElementById
(
"
test
"
)
;
var
demoDiv
=
document
.
getElementById
(
"
demo
"
)
;
demoDiv
.
innerHTML
=
"
offsetLeft:
"
testDiv
.
offsetLeft
"
offsetTop:
"
testDiv
.
offsetTop
;
Try it »
Element object