Search code examples
htmlscrollstandards

HTML - Which element has the page's scrollbar: <BODY> or <HTML>?


In a simple, compliant HTML document, where the content in the <BODY> element is of greater height than the browser's viewport, a vertical scrollbar will appear on the right (unless the scrollbar is disabled, of course).

When this happens, which element is the scrollbar attached to: <BODY> or <HTML>?


Solution

  • By default, at least in Chrome, <html>. You can test this by scrolling down on this page and comparing document.body.scrollTop to document.getElementsByTagName('html').item(0).scrollTop.

    There is nothing requiring that you maintain this choice, and you are able to override this default behavior using CSS.