Method 1: Using the offsetHeight property: The offsetHeight property of an element is a read-only property and used to return the height of an element in pixels. It includes any borders or padding of the element. This property can be used to find the height of the <div> element.
Syntax:
divElement.offsetHeight
Example:
<!DOCTYPE html> <html> <head> <title> How to get the div height using JavaScript ? </title> <style> .box { height: 100px; width: 100px; background-color: green; display:inline-block; } </style> </head> <body style="text-align:center;"> <h1 style="color: green"> GeeksforGeeks </h1> <b> Get the height of <div> element using JavaScript </b> <p> Click on the button to get the height of <div> element </p> <div class="box"></div> <p> Height of the div: <span class="output"></span> </p> <button onclick="getHeight()"> Get Height </button> <script type="text/javascript"> function getHeight() { divElement = document.querySelector(".box"); elemHeight = divElement.offsetHeight; document.querySelector(".output").textContent = elemHeight + "px"; } </script> </body> </html> |
Output:
- Before clicking the button:

- After clicking the button:

Method 2: Using clientHeight property: The clientHeight property of an element is a read-only property and used to return the height of an element in pixels. It includes only the padding applied to the element and excludes the borders, margins or horizontal scrollbars. This property can be used to find the height of the div element.
Syntax:
divElement.clientHeight
Example:
<!DOCTYPE html> <html> <head> <title> How to get the div height using JavaScript ? </title> <style> .box { height: 100px; width: 100px; background-color: green; display:inline-block; } </style> </head> <body style="text-align:center;"> <h1 style="color: green"> GeeksforGeeks </h1> <b> Get the height of <div> element using JavaScript </b> <p> Click on the button to get the height of <div> element </p> <div class="box"></div> <p> Height of the div: <span class="output"></span> </p> <button onclick="getHeight()"> Get Height </button> <script type="text/javascript"> function getHeight() { divElement = document.querySelector(".box"); elemHeight = divElement.clientHeight; document.querySelector(".output").textContent = elemHeight + "px"; } </script> </body> </html> |
Output:
- Before clicking the button:

- After clicking the button:

Method 3: Using getBoundingClientRect() Method: The getBoundingClientRect() method is used to return a DOMRect object which contains 8 properties related to the dimensions of the bounding rectangle.
One of these properties of the DOMRect object is the height property. It returns the height of the DOMRect object. This property can be used to find the height of the div element.
Syntax:
elemRect = divElement.getBoundingClientRect(); elemHeight = elemRect.height;
Example:
<!DOCTYPE html> <html> <head> <title> How to get the div height using JavaScript ? </title> <style> .box { height: 100px; width: 100px; background-color: green; display:inline-block; } </style> </head> <body style="text-align:center;"> <h1 style="color: green"> GeeksforGeeks </h1> <b> Get the height of <div> element using JavaScript </b> <p> Click on the button to get the height of <div> element </p> <div class="box"></div> <p> Height of the div: <span class="output"></span> </p> <button onclick="getHeight()"> Get Height </button> <script type="text/javascript"> function getHeight() { divElement = document.querySelector(".box"); elemRect = divElement.getBoundingClientRect(); elemHeight = elemRect.height; document.querySelector(".output").textContent = elemHeight + "px"; } </script> </body> </html> |
Output:
- Before clicking the button:

- After clicking the button:

Recommended Posts:
- How to get the height of device screen in JavaScript ?
- How to get the image size (height & width) using JavaScript ?
- How to set full-screen iframe with height 100% in JavaScript ?
- How to calculate Width and Height of the Window using JavaScript?
- HTML width/height Attribute vs CSS width/height Property
- CSS | min-height Property
- CSS | Height and Width
- CSS | max-height Property
- How to change the height of br tag?
- CSS | height Property
- p5.js | height variable
- How to fix the height of rows in the table?
- HTML | height Attribute
- How to Set full height in box-inner div using bootstrap 4 ?
- CSS | line-height Property
- HTML | <th> height Attribute
- How to get the width and height of an image ?
- Web API | DOMRect height property
- HTML | <td> height Attribute
- HTML | <img> height Attribute
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.


