1<div class="card">2 Hi3</div>4<p>Bye</p>index.htmlHi200 × 40 · x 8, y 81.card {2 width: 200px;3 height: 40px;4 background: gold;5 translate: none;6}7p { display: none; }StyleLayoutPaintCompositeDOMCSSOM.cardp200 × 40Hi16.7 ms260pxtomato40px
Left: the two files, index.html and style.cssRight: the screen, and the four stages Style, Layout, Paint, CompositeTokens: what each stage passes on, and each change running only the stages it needsLeft: the HTML (a div with the class card, and a p) and the CSS. Right: the screen, and in front of it the four rendering stages. Style works out each element's values and drops the p (display: none, no box); Layout sizes and places the card's box; Paint fills a layer, background first, then text; Composite puts the layer on the screen. Then three changes run only the stages they need: width all four, background skips Layout, translate skips Layout and Paint. Whether a translate or transform change also skips paint depends on the element having its own compositor layer. Browsers usually give one to an element while its transform or opacity is animating, and will-change: transform asks for it ahead of time.

From code to boxes

  1. Before anything is drawn, the browser has parsed the HTML into the DOM, a tree of elements, and the CSS into the CSSOM, a tree of rules. Rendering turns those trees into pixels in four stages: style, layout, paint, composite.

From boxes to pixels

What a change costs

What happens

;; step 1/10 · parse
index.html  →  DOM    div.card ("Hi"), p ("Bye")
style.css   →  CSSOM  .card, p
then, every frame that needs it:
  Style → Layout → Paint → Composite

Whether a translate or transform change also skips paint depends on the element having its own compositor layer. Browsers usually give one to an element while its transform or opacity is animating, and will-change: transform asks for it ahead of time. Each browser engine has its own names and extra stages (Chrome, for example, splits paint into recording and rasterising, and running layout again is often called reflow), but every one runs style, layout, paint and composite in this order.