Browser Internals6h estimated

HTML Parsing & the Render Tree

Difficulty
Importance

The problem

Raw HTML text arriving over the network needs to be turned into the structured DOM tree a browser can actually work with, and that DOM then needs to be filtered and combined with styling information into a second tree containing only what will actually be visible.

Why now

The DOM as a tree established the target structure; this topic explains how raw bytes become that structure — a parsing process — and introduces the render tree, a second, related tree the DOM alone doesn't capture, needed because not every DOM node is visible (display: none nodes are excluded).

Mental model

HTML parsing is building a tree from text, one tag at a time, handling the reality that real-world HTML is often malformed and must still produce a sensible result. The render tree is the DOM tree filtered and merged with computed CSS — DOM answers 'what exists,' render tree answers 'what will actually be painted,' and the two diverge exactly at invisible elements.

Requires

Unlocks

Used in

Projects

  • Compare a DOM tree to its corresponding render tree for a page containing a display: none element, and explain the difference directly
  • Deliberately write malformed HTML (unclosed tags) and inspect how the browser's parser still recovers a sensible DOM

Examples

  • An element with display: none exists in the DOM but has no corresponding node in the render tree
  • The browser's HTML parser recovers from a missing closing </div> tag using well-defined error-recovery rules, not by failing outright

Resources

Mastery checklist