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

Browser Support
| Property | |||||
|---|---|---|---|---|---|
| offsetTop | Yes | Yes | Yes | Yes | Yes |
Syntax
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:
var testDiv = document.getElementById("test");
var demoDiv = document.getElementById("demo");
demoDiv.innerHTML = "offsetLeft: " + testDiv.offsetLeft + "<br>offsetTop: " + testDiv.offsetTop;
Try it Yourself »
Other Extensions
Element Object