Render Tree & Layout
The Render Tree combines visible DOM nodes with their resolved CSSOM styles, omitting display: none subtrees while keeping visibility: hidden boxes. The Layout phase then computes the exact width, height, and (x, y) coordinates of every remaining box.
DOM + CSSOM to Physical Box Geometry
Inspect how display: none, visibility: hidden, and text nodes map into the Render Tree.
Engine matches CSSOM selectors against DOM elements to produce ComputedStyle per node.
.hidden { display: none; } .ghost { visibility: hidden; }- domNodes
- 5
- styledNodes
- 5
- omitted
- 0
Under the Hood
Blink constructs the Render Tree by pairing visible DOM nodes with resolved ComputedStyle structs, omitting display: none subtrees while keeping visibility: hidden boxes in flow. Like a carpenter's cut-list, anything marked display: none is crossed off before Layout measures widths, heights, and coordinates.
- Style Recalc: The engine resolves cascade rules for every DOM element into a
ComputedStylestruct. - Box Generation: Visible elements generate one or more layout boxes (including anonymous boxes for bare text runs and
::beforepseudo-elements). - Geometry Solving: Layout traverses the box tree to compute intrinsic sizes, line breaks, and viewport-relative coordinates.
/* Omitted from Render Tree: 0 layout cost, no box generated */
.collapsed-panel { display: none; }
/* Kept in Render Tree: reserves space and participates in Layout */
.invisible-placeholder { visibility: hidden; }Once DOM & CSSOM Construction finishes, reading geometry properties like offsetWidth prematurely triggers Layout Thrashing.
Problem Genealogy
- 1999–2015: Legacy layout engines mixed inline, block, and table state in mutable trees, causing O(n^2) reflow bugs.
- 2019+ (Blink LayoutNG / Gecko): Engines moved to immutable fragment trees, isolating layout inputs from outputs for predictable caching.
Production Pitfalls
- Toggling
display: noneon complex widgets: Destroying and rebuilding layout boxes discards cached line-breaking and intrinsic-size state. - Unbounded DOM depth: Deeply nested flex or grid containers multiply layout passes when parent and child constraints depend on each other; cap long feeds with Virtualized Lists & Windowing.
- When not to use
display: none: Avoiddisplay: nonefor elements toggled every frame or holding measured scroll positions; usevisibility: hiddenorcontent-visibility: hiddeninstead.
Connections & Logical Next Steps
- What This UnlocksBlock Formatting Context (BFC)
- What This UnlocksCSS Anchor Positioning
- What This UnlocksCSS Containment
- What This UnlocksCSS Scroll Snap
- What This UnlocksDynamic Viewport Units (dvh, svh, lvh)
- What This UnlocksPaint & Rasterization
- What This UnlocksSimulated DOM (JSDOM/HappyDOM) vs Real Browser Engines
BFCs partition the Layout box tree into independent block-flow regions.
Anchor positioning resolves inset coordinates during Layout without JS getBoundingClientRect() reads.
Layout containment prevents subtree geometry changes from invalidating ancestor boxes.
Scroll snap positions derive from laid-out child snap-area boxes and scroll-padding.
Viewport units resolve during Layout against the small, large, or dynamic viewport box.
Paint requires resolved box coordinates from Layout to record drawing bounds.
Real browser engines compute box geometry during layout; simulated DOMs return static zeros.
Render Tree construction cannot begin until DOM nodes and CSSOM rules exist.
Layout is the geometry-solving stage inside the main-thread frame pipeline.
Skipped subtrees retain their DOM nodes but bypass Layout and Paint until near the viewport.
Resolves inline and block properties to physical box edges during layout box generation.
Synchronizes nested subgrid item geometry with parent grid tracks during layout calculation.
Layout computes fractional CSS pixels before Paint snaps borders and transforms.
Full-list DOM rendering forces layout over thousands of off-screen boxes, whereas virtualization caps active layout nodes to the viewport.