EN
JavaScript - element's offsetHeight vs clientHeight
4
points
In this short article, we would like to show, what is difference between HTML element's offsetHeight
and clientHeight
in JavaScript (under web browser).
Quick answer:
offsetHeight === clientHeight + borderTopWidth + borderBottomWidth

Practical example:
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<head>
<style>
div.element {
padding: 5px;
border: 10px solid gold;
background: orange;
width: 200px;
height: 40px;
}
</style>
</head>
<body>
<div id="element" class="element">Example text inside ...</div>
<script>
var element = document.querySelector('#element');
console.log('clientHeight: ' + element.clientHeight);
console.log('offsetHeight: ' + element.offsetHeight);
/*
clientHeight === 40px (internal height) + 2 * 5px (padding size)
offsetHeight === 40px (internal height) + 2 * 5px (padding size) + 2 * 10px (border size)
|
v
offsetHeight === clientHeight + 2 * 10px (border size)
*/
</script>
</body>
</html>