HTML | DOM offsetHeight Property

The DOM offsetHeight property is used to returns the layout height of an element as an integer. It is measured in pixels. It includes height, border, padding, and horizontal scrollbars but not margin. If the element is hidden then it returns 0.

Syntax:

element.offsetHeight 

Return Value: It returns the layout height of an element as an integer.
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        DOM Style offsetWidth Property
    </title>
  
    <style>
        #GFG {
            height: 150px;
            width: 300px;
            padding: 10px;
            margin: 15px;
            background-color: green;
        }
    </style>
</head>
  
<body>
    <h2>DOM offsetHeight Property</h2>
  
    <div id="GFG">
        <b>Information about this div:</b>
  
        <p id="sudo"></p>
    </div>
  
    <button type="button" onclick="Geeks()">
        Submit
    </button>
  
    <script>
        function Geeks() {
  
            var elmnt = document.getElementById("GFG");
  
            var txt = "Height including padding and border: "
                + elmnt.offsetHeight + "px";
  
            document.getElementById("sudo").innerHTML = txt;
        }
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before Clicking On Button:
  • After Clicking On Button:

Example-2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>
        DOM Style offsetWidth Property
    </title>
  
    <style>
        #GFG {
            height: 150px;
            width: 300px;
            padding: 10px;
            margin: 15px;
            background-color: green;
        }
    </style>
</head>
  
<body>
    <h2>DOM offsetHeight Property</h2>
  
    <div id="GFG">
        <b>Information about this div:</b>
        <br>
  
        <p id="sudo"></p>
    </div>
  
    <button type="button" onclick="Geeks()">
        Submit
    </button>
  
    <script>
        function Geeks() {
            var elmnt = document.getElementById("GFG");
            var txt = "";
            txt += "Height with padding: " 
                + elmnt.clientHeight + "px<br>";
  
            txt += "Height with padding and border: " 
                + elmnt.offsetHeight + "px";
  
            document.getElementById("sudo").innerHTML = txt;
        }
    </script>
</body>
  
</html>

chevron_right


Output :

  • Before Clicking On Button:
  • After Clicking On Button:

Supported Browsers: The browser supported by DOM offsetHeight property are listed below:

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.