How to get the div height using JavaScript ? Improve Improve Improve Like Article Like Save Article Save Share Report issue Report In this article, we will see How to get the div height using Javascript. We can do this by following ways: Using the offsetHeight property.Using the clientHeight property.Using getBoundingClientRect() Method. Method 1: Using the offsetHeight property: The offsetHeight property of an element is a read-only property and is 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: In this example, we will use the offsetHeight property. html <style> .box { height: 100px; width: 100px; background-color: green; display: inline-block; }</style><h1 style="color: green"> GeeksforGeeks</h1> <b> Get the height of <div> element using JavaScript </div></b> <p> Click on the button to get the height of 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> Output: <img src="https://media.geeksforgeeks.org/wp-content/uploads/20230120173052/gfg.gif" alt="How to get the height using JavaScript ?” srcset=”https://media.geeksforgeeks.org/wp-content/uploads/20230120173052/gfg.gif 276w, ” sizes=”100vw” width=”276″>How to get the <div> height using JavaScript ? Method 2: Using clientHeight property: The clientHeight property of an element is a read-only property and is 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: In this example, we will use the clientHeight property. html <!-- HTML elements to iterate --><style> .box { height: 100px; width: 100px; background-color: green; display: inline-block; }</style><h1 style="color: green"> GeeksforGeeks</h1> <b> Get the height of <div> element using JavaScript </div></b> <p> Click on the button to get the height of<div> element</div></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> Output: <img src="https://media.geeksforgeeks.org/wp-content/uploads/20230120173052/gfg.gif" alt="How to get the height using JavaScript ?” srcset=”https://media.geeksforgeeks.org/wp-content/uploads/20230120173052/gfg.gif 276w, ” sizes=”100vw” width=”276″>How to get the <div> height using JavaScript ? 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: In this example, we will see the use of getBoundingClientRect() Method html <style> .box { height: 100px; width: 100px; background-color: green; display:inline-block; }</style><h1 style="color: green"> GeeksforGeeks</h1> <b> Get the height of <div> element using JavaScript </div></b> <p> Click on the button to get the height of <div> element </div></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> Output: <img src="https://media.geeksforgeeks.org/wp-content/uploads/20230120173052/gfg.gif" alt="How to get the height using JavaScript ?” srcset=”https://media.geeksforgeeks.org/wp-content/uploads/20230120173052/gfg.gif 276w, ” sizes=”100vw” width=”276″>How to get the <div> height using JavaScript ? Last Updated : 26 Apr, 2023 Like Article Save Article Previous Find 1st January be Sunday between a range of years in JavaScript ? Next How to select all elements without a given class using jQuery ? Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads How to force child div to be 100% of parent div's height without specifying parent's height? How to expand floated child div's height to its parent's height in CSS ? How to dynamically get the content height of a div using AngularJS ? How to get the height of a div using jQuery ? How to get the height of sibling div and send data to sibling component in Angular? How to overlay one div over another div using CSS How to copy the content of a div into another div using jQuery ? How to Make a Child Div Element Wider than Parent Div using CSS ? How to center a div within another div? How to center a div on the edge of another div in SASS ? Complete Tutorials Statistics Cheat Sheet React Bootstrap Tutorial JavaScript Programming Examples CSS Examples HTML Examples Like sayantanm19 Follow Article Tags : JavaScript-Questions Picked JavaScript Web Technologies Additional Information Vote for difficulty : Easy Normal Medium Hard Expert Improved By : shobhit_sharmamansigeekso9ii