Rendering PipelineBaseline · Widely

DOM & CSSOM Construction

Mental Model

The HTML parser incrementally builds the DOM tree while the CSS parser builds the CSSOM tree. Because JavaScript can query styles via getComputedStyle(), any synchronous <script> pauses DOM construction until every preceding stylesheet finishes building the CSSOM.

Interactive Simulator

Parser Blocking: HTML + CSSOM + Sync Script

Step through how a synchronous script stalls DOM construction while waiting on CSSOM.

HTML Parser
CSSOM
Sync Script
Step 1 / 4: 1. Byte Stream to HTML Tokens

The HTML tokenizer converts UTF-8 bytes into StartTag and EndTag tokens incrementally.

<link rel="stylesheet" href="/app.css">
Internal State / Memory
domNodes
4
cssomReady
false
parserState
running

Under the Hood

Like a dual-track railway converging at a single switchyard, HTML and CSS arrive as raw byte streams that must become structured trees before layout begins.

  1. Tokenization: The engine decodes bytes into characters, then emits tokens (StartTag, Text, EndTag for HTML; selectors and declarations for CSS).
  2. Tree Construction: HTML tokens append Element nodes to the DOM incrementally; CSS rules form a cascade-indexed CSSOM tree.
  3. The Serialization Trap: When the HTML parser hits a non-async, non-defer <script>, it halts DOM construction until CSSOM completes, preventing scripts from reading stale styles.
HTML
<head>
  <!-- Render-blocking: CSSOM must finish before first paint -->
  <link rel="stylesheet" href="/styles.css" />
  <!-- Parser-blocking: waits for CSSOM, then halts DOM -->
  <script src="/analytics.js"></script>
  <!-- Non-blocking: downloads in parallel, runs after DOM -->
  <script defer src="/app.js"></script>
</head>

Use Preload Scanner Hints to fetch subresources early while the main Browser Rendering Pipeline waits on CSSOM.

Problem Genealogy

  • 1995–2008: Blocking <script> tags at the top of <head> froze page rendering until every script downloaded and executed.
  • 2009 (HTML5): async and defer attributes decoupled script downloading from HTML tokenization.
  • 2015+: HTTP/2 multiplexing and preload hints reduced round-trip stalls, yet render-blocking CSSOM remains mandatory to avoid unstyled flashes.

Production Pitfalls

Production Pitfall
  • CSS-before-script deadlock: Placing a small inline <script> after a slow external <link rel="stylesheet"> turns a render-blocking stylesheet into a full parser blocker.
  • CSSOM @import chains: Nesting @import inside stylesheets hides secondary CSS files from the preload scanner, adding serial network round-trips.
When Not to Use
  • When not to use synchronous scripts: Never place synchronous <script> tags in <head> unless the script mutates critical above-the-fold state before first paint (such as theme class hydration).

Connections & Logical Next Steps