English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
offsetHeightA read-only property that returns the height of the element in integer form, including vertical padding and borders.
Generally, offsetHeight is the pixel measurement of the element's CSS height, including any borders, padding, and horizontal scrollbars (if any). It does not include the height of pseudo-elements such as::beforeor::after.
To understand this attribute, you must understandCSS Box Model.
UsingclientHeightandclientWidthThe attribute returns the visible height and width of the element, including padding, but not including borders, margins, and scrollbars (if any).
element.offsetHeight
var elem = document.querySelector("div"); var txt = "Height includes padding" +border: "" + elem.offsetHeight + "px<br>"; txt += "Width includes padding" + border: "" + elem.offsetWidth + "px";Test and See‹/›
All browsers fully support the offsetHeight property:
Property | |||||
offsetHeight | Yes | Yes | Yes | Yes | Yes |
Return Value: | A number, in pixels, representing the height of an element including padding, border, and scrollbar |
---|
This example demonstrates the difference between clientHeight and offsetHeight:
var elem = document.querySelector("div"); var txt = "Height includes padding: " + elem.clientHeight + "px<br>"; txt +="Height includes padding" + border: "" + elem.offsetHeight + "px";Test and See‹/›
HTML DOM Reference:offsetWidth property
HTML DOM Reference:offsetLeft property
HTML DOM Reference:offsetTop property
HTML DOM Reference:offsetParent property