• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

The Problem

The browser receives CSS as text (from stylesheets, <style> tags, inline styles). To apply styles, the browser needs a structured representation of all CSS rules. Raw text isn’t programmable.

Core Idea

CSS parsing converts CSS text into the CSSOM (CSS Object Model)—a tree of style rules. This is used later to compute styles for each DOM element during render tree construction.

How It Works

  1. Tokenization: Break CSS text into tokens (selector, {, property, value, })
  2. Parse rules: Build CSSOM tree with selectors and declarations
    body { color: red; }
    ↓
    CSSOM: selector=body, declarations=[color: red]
    
  3. Style calculation: Later, match CSSOM rules to DOM elements

CSS parsing can block rendering—browser won’t paint until CSSOM is ready.

Visual Explanation

G CSS CSS Text CSSOM CSSOM Tree (selector + rules) CSS->CSSOM RenderTree Render Tree (DOM + CSSOM combined) CSSOM->RenderTree

Key Properties

  • CSSOM is separate from DOM (different trees)
  • CSS parsing blocks rendering (need styles before paint)
  • Media queries are evaluated during CSSOM construction
  • Errors in CSS are silently ignored (lenient parsing)

Connections

Edge Cases & Gotchas

  • CSS at top of page (best practice)—blocks rendering until parsed
  • @import causes additional network requests (slow)
  • Invalid CSS silently fails (no error thrown)
  • Large stylesheets = slow CSSOM construction