The linked Q&A in the comments does not explain this well, and focusses mostly on the general difference between the heights. However, the accepted answer does itself link to a MDN page which does mention the relevant matter.
You are right, the root element (i.e. the <html> element in a valid HTML document) is special.
The first thing to understand is that the height of the root element is not, by default, the height of the viewport (unless the document is in quirks mode). The height of the root element by default is "auto", which means the height of the in-flow content that it contains.
The offsetHeight attribute must return the result of running these steps:
If the element does not have any associated CSS layout box return zero and terminate this algorithm.
Return the border edge height of the first CSS layout box associated with the element, ignoring any transforms that apply to the element and its ancestors.
This then is simple, it’s the height of the <html> element’s border box.
If the element has no associated CSS layout box or if the CSS layout box is inline, return zero.
If the element is the root element and the element’s node document is not in quirks mode, or if the element is the HTML body element and the element’s node document is in quirks mode, return the viewport height excluding the size of a rendered scroll bar (if any).
Return the height of the padding edge excluding the height of any rendered scrollbar between the padding edge and the border edge, ignoring any transforms that apply to the element and its ancestors.
So the clientHeight of the <html> element is not the height of its padding box as it is with other elements, but the height of the viewport. Which accounts for the large difference you see.
2
Answers
client height =
the height of an element + the vertical padding
clientheight
does not include scrollbar, margin or border.while on the other hand
offset height =
the height of the element + the vertical padding + the top and bottom borders + the horizontal scrollbar (if it's available)
offsetheight
includes scrollbar , margin and border.The linked Q&A in the comments does not explain this well, and focusses mostly on the general difference between the heights. However, the accepted answer does itself link to a MDN page which does mention the relevant matter.
You are right, the root element (i.e. the
<html>
element in a valid HTML document) is special.The first thing to understand is that the height of the root element is not, by default, the height of the viewport (unless the document is in quirks mode). The height of the root element by default is "auto", which means the height of the in-flow content that it contains.
So the definition of offsetHeight says
This then is simple, it’s the height of the
<html>
element’s border box.However, the definition of clientHeight says
So the clientHeight of the
<html>
element is not the height of its padding box as it is with other elements, but the height of the viewport. Which accounts for the large difference you see.