it's actually pretty logic. First of all and
tags are required tags in a webpage. Where the
tag contains all of the
code the
tag holds all of the contents.
Consider this standard structure for a basic HTML
document:
The spec defines as the root element of a document, and we can clearly see that in the above example: the element is the very top level of all other elements. The buck stops there because there are no more levels beyond that from which styles can be inherited.
From there, and make up the only two elements that fall directly inside . In fact, the spec defines directly in contrast to since those are the only two elements that need to be distinguished.
So, the bottom line here is that is the root element of a document where is a descendent contained within it. In fact, there is a :root selector in CSS. These target the exact same thing.
It's tempting to think that any styles we want to be inherited across the board should be applied directly to because it is the root element of the document.
supersedes
in hierarchy, so it follows that it must contain all global styles.
But that's not exactly the case. In fact, inline attributes for the following were originally assigned to in the spec:
The background-color
There is a weird thing in CSS
where the background-color
on floods the whole viewport even if the metrics of the element itself don't cover that whole area. Unless the
background-color
gets set on the html element, then it doesn't.
If flooding is the goal, it can be smart to just set it on the html
element to begin with.