Parsing CSS into the CSSOM
What you'll learn: How browsers convert your CSS rules into a structured tree they can use to style your web page.
When you learned about parsing HTML into the DOM, you saw how browsers turn markup into a tree of objects. The browser does something very similar with CSS, creating what's called the CSSOM (CSS Object Model).
What is the CSSOM?
Just like the DOM is a tree representation of your HTML, the CSSOM is a tree representation of all your CSS styles. After the browser finishes parsing your HTML into the DOM, it looks for all CSS (whether in <style> tags, <link> tags pointing to external stylesheets, or inline styles) and parses each rule.
How CSS Becomes the CSSOM
Think of the CSSOM as a styling instruction manual organized by importance. The browser:
- Reads all CSS sources (external files,
<style>tags, inline styles) - Parses each rule — breaking down selectors like
body,h1,.buttonand their properties - Builds a tree structure that mirrors the cascade and inheritance rules of CSS
- Calculates specificity to know which styles win when rules conflict
For example, if your CSS says body { color: black; } and p { color: blue; }, the CSSOM knows that paragraphs inherit black from body but override it with blue.
Why Does This Matter?
The browser cannot render anything until both the DOM and CSSOM are ready. It needs to match CSS rules to DOM elements to know what each element should look like. CSS is render-blocking — the page won't display until stylesheets are parsed.
Key Takeaway: The CSSOM is the browser's structured representation of all CSS rules, built by parsing stylesheets just like HTML is parsed into the DOM—both trees are required before rendering can begin.