Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

HTML | DOM offsetTop Property

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

Syntax: 

object.offsetTop

Return Value:  

  • A number in pixel unit represents the top position of element.

Example:  

HTML




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


Output: 
Before clicking on the button: 

After clicking on the button:  

Supported Browsers: 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Internet Explorer 5.5 and above
  • Firefox 1 and above
  • Opera 8 and above
  • Safari 3 and above

My Personal Notes arrow_drop_up
Last Updated : 10 Aug, 2022
Like Article
Save Article
Similar Reads
Related Tutorials