English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
clientHeightA read-only property that returns the visible height of the element (in pixels), including padding but not including borders, margins, and horizontal scrollbar (if it exists).
The clientHeight can be calculated as: CSS height+ CSS padding-the height of the horizontal scrollbar (if it exists).
To understand this property, you must understandCSS Box Model.
UsingoffsetHeightThe property returns the visible height of the element, including padding, border, and horizontal scrollbar.
element.clientHeight
var elem = document.querySelector("div"); var txt = "Height including padding: " + elem.clientHeight + "px<br>"; txt += "Width including padding: " + elem.clientWidth + "px";Test and See‹/›
All browsers fully support the clientHeight property:
Property | |||||
clientHeight | Yes | Yes | Yes | Yes | Yes |
Return Value: | A number, in pixels, representing the height of an element, including padding |
---|
This example demonstrates the difference between clientHeight and offsetHeight:
var elem = document.querySelector("div"); var txt = "Height + padding: "" + elem.clientHeight + "px<br>"; txt += "Height + padding + border: "" + elem.offsetHeight + "px";Test and See‹/›
HTML DOM Reference:HTML DOM offsetHeight Property
HTML DOM Reference:HTML DOM scrollHeight Property
CSS Reference:CSS overflow Property