Skip to content
Preptima
mediumConceptScenarioMidSeniorStaff

Walk me through what the browser does between receiving the HTML and the first paint, and tell me why layout thrashing is expensive

6 min readUpdated 2026-08-15

Answer

Short answer

The browser parses HTML into the DOM and CSS into the CSSOM, combines them into a layout tree, then runs style, layout, paint and composite. Reading a geometry property after a write forces the browser to flush layout early, so a loop that interleaves reads and writes pays for a full layout every iteration.

Was this answer helpful?

Likely follow-ups

  • Why does a stylesheet that is still in flight delay execution of a classic script that appears after it?
  • A designer wants an element's height animated from 0 to auto. What do you build instead, and what do you lose?
  • How do `contain: layout` and `content-visibility: auto` change what a layout costs?
  • A requestAnimationFrame callback calls getBoundingClientRect on two hundred elements and writes nothing at all. Is that layout thrashing?

Related questions

Further reading