Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between offsetHeight and scrollHeight of an element in DOM?

In the DOM, what is the difference between an element’s offsetHeight and its scrollHeight? An image in explanation would be a great help.

like image 255
user2943607 Avatar asked Nov 01 '13 02:11

user2943607


People also ask

What is scrollTop clientHeight and scrollHeight?

clientHeight: It returns the height of an HTML element including padding in pixels but does not include margin, border and scrollbar height. Syntax: element.clientHeight. scrollHeight: It returns the height of the content enclosed in an html element including padding but not margin, border and scroll bar.

What is element offsetHeight?

The HTMLElement. offsetHeight read-only property returns the height of an element, including vertical padding and borders, as an integer. Typically, offsetHeight is a measurement in pixels of the element's CSS height, including any borders, padding, and horizontal scrollbars (if rendered).

What is scrollHeight property?

The scrollHeight property returns the height of an element including padding, but excluding borders, scrollbars, or margins. The scrollHeight property returns the height in pixels. The scrollHeight property is read-only.

What is clientHeight?

Definition and Usage The clientHeight property returns the viewable height of an element in pixels, including padding, but not the border, scrollbar or margin. The clientHeight property is read-only.

What is the difference between htmlelement offsetheight and scrollheight?

HTMLElement.offsetHeight is a measurement which includes the element borders, the element vertical padding, the element horizontal scrollbar (if present, if rendered) and the element CSS height. HTMLElement.scrollHeight is a measurement of the height of an element's content including content not visible on the screen due to overflow.

What is offsetheight in CSS?

OffsetHeight: It is the property that helps to measure the visible height of an element in terms of pixels including the CSS properties like element visible content, vertical padding, border, and scrollbar but not top and bottom margin.

What is the difference between clientheight and scrollheight?

clientHeight property returns the viewable height of an element in pixels, including padding, but not the border, scrollbar or margin. ScrollHeight is all the scrollable area, so your scroll will never run over your margin or border, so that's why scrollHeight doesn't include margin or borders but yeah padding does.

What is the difference between offset height and scroll height?

As @Csarsam said, offset height is the border-box height (I'm rewording). Scroll height, is the height of the scrollable content, which is generally composed of multiple elements.


1 Answers

HTMLElement.offsetHeight is a measurement which includes the element borders, the element vertical padding, the element horizontal scrollbar (if present, if rendered) and the element CSS height. HTMLElement.scrollHeight is a measurement of the height of an element's content including content not visible on the screen due to overflow. The value returned by HTMLElement.scrollHeight WILL include the padding-top and padding-bottom, but will NOT include the element borders or the element horizontal scrollbar.

This page and this page are my sources.

The MDN documentation also provides images to demonstrate.

like image 75
Csarsam Avatar answered Oct 07 '22 22:10

Csarsam