205 of 264 menu

offsetTop property

The offsetTop property contains the top offset of an element relative to offsetParent. Contains the distance from offsetParent to the element's border.

Syntax

element.offsetTop;

Example

Let's find the offset of an element relative to its own offsetParent:

<div id="parent" style="position: relative;"> <div id="elem" style="position: absolute; top: 100px;"></div> </div> let elem = document.querySelector('#elem'); console.log(elem.offsetTop);

The code execution result:

100

Example

Margins are also included into offset:

<div id="parent" style="position: relative;"> <div id="elem" style="position: absolute; top: 100px; margin: 50px;"></div> </div> let elem = document.querySelector('#elem'); console.log(elem.offsetTop);

The code execution result:

150

See also

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline