I've been researching browser rendering and I've just now come to the part in the render process where the browser constructs the CSSOM from raw CSS.
In all of the tutorials I've seen the authors seem to make the assumption/assertion that the body
element is the root, and that all styles applied to the body will tacitly be applied to the rest of the DOM unless explicitly overridden by another selector. An example of this is here https://blog.logrocket.com/how-css-works-parsing-painting-css-in-the-critical-rendering-path-b3ee290762d3/
In both of these explanations- the body
tag is assumed to be the root, even though the html
tag seems like it should be the root. Whats more is the fact that the HTML specification doesn't seem to require EITHER of these tags in markup (maybe I'm misunderstanding this though).
To me this seems like an incredibly important piece of information when applying styles to elements in the render tree. If one does not know which element is the root, then one does not know how the styles should cascade onto one another.
So my question is essentially, do browsers always assume that the body element is the root, or is there a method for determining which element should be the root in the browser's CSS Tree?