--- title: HTMLElement.offsetTop slug: Web/API/HTMLElement/offsetTop translation_of: Web/API/HTMLElement/offsetTop ---
{{ APIRef("HTML DOM") }}
Властивість лише для зчитування HTMLElement.offsetTop повертає відстань від поточного елемента відносно верху {{domxref("HTMLelement.offsetParent","offsetParent")}} .

Синтакс

topPos = element.offsetTop;

Параметри

Приклад

var d = document.getElementById("div1");
var topPos = d.offsetTop;

if (topPos > 10) {
  // object is offset more
  // than 10 pixels from its parent
}

Специфікація

Специфіуація Статус Коментар
{{SpecName('CSSOM View', '#dom-htmlelement-offsettop', 'offsetTop')}} {{Spec2('CSSOM View')}}  

Браузерна сумісність

{{Compat("api.HTMLElement.offsetTop")}}

In compliance with the specification, this property will return null on Webkit if the element is hidden (the style.display of this element or any ancestor is "none") or if the style.position of the element itself is set to "fixed".

This property will return null on Internet Explorer (9) if the style.position of the element itself is set to "fixed". (Having display:none does not affect this browser.)