English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML DOM offsetTop property

HTML DOM Element Object

offsetTopIt is a read-only property that returns the distance from the top inner padding of the current element to its offsetParent element.

The returned value includes:

  • The top position and margin of the element

  • The top padding, scrollbar, and border of the offsetParent element

Note:ThisoffsetParentThe element is the nearest parent element whose position is not static.

To return the left position of the element, useoffsetLeftProperty.

Syntax:

element.offsetTop
var myBox = document.getElementById("box");
document.getElementById("result").innerHTML = myBox.offsetTop;
Test and See‹/›

Browser Compatibility

All browsers fully support the offsetTop property:

Property
offsetTopYesYesYesYesYes

Technical Details

Return Value:A number representing the top position of the element, in pixels
DOM Version:CSS Object Model (CSSOM)

More Examples

Return the position of the DIV element:

var myBox = document.getElementById("box");
var x = document.getElementById("result");
x.innerHTML = "offsetLeft:  " + myBox.offsetLeft + "<br>offsetTop:  " + myBox.offsetTop;
Test and See‹/›

Related References

HTML DOM Reference:offsetHeight property

HTML DOM Reference:offsetWidth property

HTML DOM Reference:offsetLeft property

HTML DOM Reference:offsetParent property

HTML DOM Element Object