HTML DOM clientHeight Property

元素对象参考手册Element Object

Example

Get the height of the div element, including padding:

var elmnt = document.getElementById("myDIV"); var txt = "The height of the div element, including padding:" + elmnt.clientHeight + "px<br>"; txt += "The width of the div element, including padding:" + elmnt.clientWidth + "px";

Try it Yourself »

Definition and Usage

The clientHeight property is a read-only property. It returns the pixel height of the element. The height includes padding, but does not include border, margin, or scrollbar. It is an integer, and the unit is pixels (px).

clientHeight can be calculated as CSS height + CSS padding - horizontal scrollbar height (if it exists).

For the document's body object, it includes the total content height in place of the element's CSS height. The height of content extending downward from floating elements is ignored.

Note:To understand this property, please refer toCSS Box Model。

Tip:This property is usually used together withclientWidththe property.

Tip:Use offsetHeightandoffsettWidthproperty to return the visible height and width of the element, including padding and border.

Tip:To add a scrollbar to the element, you can useoverflowthe property.

This is a read-only property.


Browser Support

Property
clientHeight Yes Yes Yes Yes Yes

Syntax

element.clientHeight 

Technical Details

Return Value: Returns an integer representing the pixel height of the element.

More Examples

Example

The following example demonstrates the difference between the clientHeight/clientWidth and offsetHeight/offsetWidth properties:

var elmnt = document.getElementById("myDIV"); var txt = ""; txt += "Height includes padding:" + elmnt.clientHeight + "px<br>"; txt += "Height includes padding and border:" + elmnt.offsetHeight + "px<br>"; txt += "Width includes padding:" + elmnt.clientWidth + "px<br>"; txt += "Width includes padding and border:" + elmnt.offsetWidth + "px";

Try it Yourself »

Example

The following example demonstrates the difference between the clientHeight/clientWidth and offsetHeight/offsetWidth properties after adding a scrollbar to the element:

var elmnt = document.getElementById("myDIV"); var txt = ""; txt += "<b>Style information of div:</b><br>"; txt += "Height includes padding:" + elmnt.clientHeight + "px<br>"; txt += "Height includes padding, border, and scrollbar:" + elmnt.offsetHeight + "px<br>"; txt += "Width includes padding:" + elmnt.clientWidth + "px<br>"; txt += "Width includes padding, border, and scrollbar:" + elmnt.offsetWidth + "px";

Try it Yourself »


元素对象参考手册Element Object

Other Extensions