Skip to content
Related Articles

Related Articles

Improve Article
HTML | DOM offsetTop Property
  • Last Updated : 26 Jul, 2019

The DOM offsetTop property is used to return the top position which is relative to the top of the offsetParent element.



Return Value:

  • A number in pixel unit which is repersent the top position of element.


    <!DOCTYPE html>
            #offsetdiv {
                top: 80px;
                margin: 20px;
                padding: 10px;
                width: 350px;
                position: absolute;
                border: 5px solid green
        <h3>Geeks for Geeks</h3>
        <h3>HTML DOM offsetTop property</h3>
        <div id="offsetdiv">
                <button onclick="GFGfunction()">Try it</button>
            <p>offsetTop is: <span id="gfg"></span></p>
            function GFGfunction() {
                var x = document.getElementById("offsetdiv");
                document.getElementById("gfg").innerHTML =

    Before clicking on the button:

    After clicking on the button:

    Supported Browsers:

    • Google Chrome
    • Internet Explorer 4.0
    • Firefox
    • Opera
    • Safari

    My Personal Notes arrow_drop_up
  • Recommended Articles
    Page :