Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Differences Between clientHeight and offsetHeight in JavaScript



You can use 2 properties, clientHeight and offsetHeight to get the height of the div.

clientHeight includes padding of the div.

offsetHeight includes padding, scrollBar, and borders of the div.

Example

For example, if you have the following HTML −

<div id="myDiv" height="400px"></div>

You can get the height using −

const height = document.querySelector('#myDiv').offsetHeight
console.log(height)

Output

This will give the output −

400
Updated on: 2019-12-02T05:57:09+05:30

301 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements