Open In App
Related Articles

HTML DOM offsetTop Property

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.



Return Value: A number in the pixel unit represents the top position of the element.

Example: In this example, we will use DOM offsetTop property 


<!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() {
            let x = document.getElementById("offsetdiv");
            document.getElementById("gfg").innerHTML =



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

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 13 Jun, 2023
Like Article
Save Article
Similar Reads
Complete Tutorials