YouTip LogoYouTip

Prop Element Offsettop

# HTML DOM offsetTop Property [![Image 4: Element Object Reference Manual](#) Element Object](#) ## Example Get the top offset of a div element: ```javascript var testDiv = document.getElementById("test"); document.getElementById("demo").innerHTML = testDiv.offsetTop; [Try it Yourself Β»](#) * * * ## Definition and Usage The `offsetTop` property is a read-only property that returns the number of pixels that the upper outer border of the current element is offset to the top within the `offsetParent` node. The returned value includes: * The top offset of the element in pixels, including the element's margin * The top padding, border, and scrollbar of the `offsetParent` element **Note:** The (#) property is 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, body, or ancestor element. **Tip:** Use the (#) property to get the left offset of an element. !(#) * * * ## Browser Support | Property | | | | | | | --- | --- | --- | --- | --- | --- | | offsetTop | Yes | Yes | Yes | Yes | Yes | * * * ## Syntax ```javascript element.offsetTop ## Technical Details | Return Value: | Returns an integer representing the top 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 Yourself Β»](#) * * Element Object](#)
← Docker Top CommandProp Element Offsetleft β†’