FACTS:
clientHeight: Returns the height of an element, including padding
offsetHeight: Returns the height of an element, including padding, border and scrollbar
Conclusion:
offsetHeight should return more pixels than clientHeight. offsetHeight is bigger than clientHeight.
Question:
When I use these two properties on HTML tag, it returns 8 from offsetHeight and 778 from clientHeight.
Why's that? offsetHeight should be bigger than clientHeight, shouldn't it?
Then why is it only 8 pixels? What's happening here?
Code:
<!DOCTYPE html> <html id = "foo"> <body> <script> var element = document.getElementById('foo'); var osHeight = element.offsetHeight; var cHeight = element.clientHeight; document.write("Offset Height is " + osHeight + "<br/>"); document.write("Client Height is " + cHeight); </script> </body> </html> Output:
Offset Height is 8 Client Height is 778 
htmlelement. There is nothing taking up space in the document, and you haven't set a height, so the height is really just 8 pixels, likeoffsetHeightreturns, butclientHeightis returning the visible height of the document, which is different.