YouTip LogoYouTip

Prop Element Offsetleft

# HTML DOM offsetLeft Property [![Image 4: Element Object Reference Manual](#) Element Object](#) ## Example Get the left offset of a div element: ```javascript var testDiv = document.getElementById("test"); document.getElementById("demo").innerHTML = testDiv.offsetLeft; [Try it Β»](#) * * * ## Definition and Usage The `offsetLeft` property is a read-only property that returns the number of pixels that the upper left corner of the current element is offset to the left within the `offsetParent` node. The return value includes: * The number of pixels the element is shifted to the left, the element's margin * The left padding, border, and scrollbar of the `offsetParent` element **Note:** The (#) property returns a reference to the nearest ancestor element that is positioned (i.e., has a position value other than `static`) or the nearest table, table cell, or ancestor element with a `display` value of `table-cell`. **Tip:** Use the (#) property to get the top offset of an element. !(#) * * * ## Browser Support | Property | | | | | | | --- | --- | --- | --- | --- | --- | | offsetLeft | Yes | Yes | Yes | Yes | Yes | * * * ## Syntax ```javascript element.offsetLeft ## Technical Details | Return Value: | Returns an integer representing the left offset of the element in pixels (px). | | :--- | * * * ## More Examples ## Example Get the position of a div element: ```javascript var testDiv = document.getElementById("test"); var demoDiv = document.getElementById("demo"); demoDiv.innerHTML = "offsetLeft: " + testDiv.offsetLeft + "
offsetTop: " + testDiv.offsetTop; [Try it Β»](#) * * Element Object](#)
← Prop Element OffsettopDocker Create Command β†’