Easy Tutorial
❮ Prop Frame Marginwidth Prop Pushbutton Value ❯

HTML DOM offsetTop Property

Element Object

Example

Get the top offset of a div element:


Definition and Usage

offsetTop is a read-only property that returns the offset in pixels of the current element relative to the top boundary of the offsetParent node.

The return value includes:

Note: The offsetParent element is a reference to the nearest positioned ancestor (in terms of containment hierarchy) or the nearest table cell element.

Tip: To get the left offset of an element, use the offsetLeft property.


Browser Support

Property Chrome Edge Firefox Safari Opera
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. | | --- | --- |


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;

Element Object

❮ Prop Frame Marginwidth Prop Pushbutton Value ❯