How it works
Parse. The HTML Standard's parsing model runs bytes through encoding detection (a <meta charset> in the first 1,024 bytes is found by a prescan), a tokenizer state machine, and tree construction, which inserts elements by insertion mode and repairs mis-nested markup. The parser runs inside the event loop and can be paused: a classic <script> without async or defer stops tree construction until it has run.
Style. Selector matching finds the rules for each element; the cascade picks a winner per property; inheritance and value computation turn em, currentcolor and var() into computed values.
Layout. Box generation applies display: none drops a subtree, contents drops the element's own box but keeps its children's, and anonymous boxes wrap stray text and inline runs. Each box joins a formatting context (block, inline, flex, grid) whose rules size it. In Chromium, LayoutNG produces an immutable fragment tree of positioned fragments.
Paint. Paint walks the layout result in the order CSS 2 Appendix E defines. Within each stacking context: its background, children with negative z-index, block backgrounds, floats, inline content, then positioned descendants and positive z-index children. Chromium's pre-paint stage first builds property trees (transform, clip, effect, scroll), so paint can emit display items that refer to them.
Composite. Chromium commits property trees and the display list to the compositor thread, layerizes the list, rasterizes tiles on raster threads and the GPU, and the Viz process aggregates frames from all tabs and draws them. In Firefox, the content process serialises a WebRender display list and sends it to the GPU process, which builds a scene, culls it to a frame, and renders it on the GPU.
Edge cases
Which stages a change dirties is visible in Chrome through the DevTools Protocol. This snippet reads Performance.getMetrics (RecalcStyleCount, LayoutCount) before and after each change, each followed by an offsetWidth read to force style and layout:
// <div id="box" style="width: 100px">: static position, no transform yet
box.style.color = 'red';
// → style +1, layout +0
box.style.width = '120px';
// → style +1, layout +1
box.style.transform = 'translateX(10px)';
// → style +1, layout +1
box.style.transform = 'translateX(20px)';
// → style +1, layout +0
box.style.left = '5px';
// → style +1, layout +0
Chrome 156 only; three runs gave identical counts. left on a statically positioned box doesn't apply, so layout stays clean. The first switch from no transform to a transform ran layout once; later transform changes didn't.
- Hidden documents. Update the rendering skips documents that are hidden or render-blocked, so they don't style, lay out or paint until shown.
- Skipped subtrees.
content-visibility: hidden always skips its contents; auto skips them while they aren't relevant to the user. Reading geometry inside them still works: the browser styles and lays them out on demand (Chrome 156 logs a console warning), which throws the saving away.
Real-world scenario
A feed renders 3,000 cards, each with a heading and two long paragraphs. Resizing the container relaid every card: in a test page, forcing layout after a width change took 45–55 ms in Chrome 156 and 41–45 ms in Firefox 159 (15 measurements each, 3 page loads). Adding content-visibility: auto; contain-intrinsic-size: auto 120px to each card dropped it to 1–2 ms in both, because off-screen cards are size-contained placeholders whose contents layout skips. The cost moves to scroll time, when cards near the viewport are laid out for the first time.
Trade-offs
A staged, retained pipeline lets the browser cache each stage's output and redo only what a change dirtied, and lets compositing run on other threads. The price is that cost depends on which stage a property dirties: the same visual change is cheap as a transform and expensive as margin-left or width. Extra layers speed up animation but cost GPU memory, and very large DOMs make every style and layout pass slower whatever was changed.