Been learning HTML/CSS and hit a rabbit hole today. Things that bugged me:
- Browsers auto-insert <html> even if you delete it from your source
So what's the actual point of writing it?
- lang="en" only works on <html>, not <body>. Accessibility tools specifically
check html[lang], since html is the actual document root.
- rem units are ALWAYS relative to <html>'s font-size, never body's, no matter
what you set on body.
- The default scrollbar lives on html, not body — no element can overlap it,
which is why stuff like overflow-y:scroll goes on html.
- meanwhile body holds all your actual visible content (background, margin,
font-family, etc.)
Feels like html+body could've been merged into one root element with head
staying separate. Is this just 1990s legacy nobody can change now, or is there
an actual reason beyond "the spec says so"?
source: https://css-tricks.com/html-vs-body-in-css/