The Rendering Pipeline

An interactive tutorial on the browser rendering pipeline, from bytes to pixels: parsing, style, layout, paint and compositing, measured in real Chrome.

A frontend app built by Ananda Rizki. More of them at Labs.

Labs — by Ananda Rizki

The Rendering Pipeline

Tutorial

A first-principles tutorial on the browser's rendering pipeline. It opens by explaining what a browser is actually being asked to do — you hand it a string of bytes and it has to produce a rectangle of coloured pixels, sixty times a second — and works through the machine that does it: tokenizing HTML into a stream of tokens, building a DOM tree from them, parsing CSS into the CSSOM, combining the two into the tree that actually gets drawn, laying that tree out into boxes with real coordinates, painting those boxes into lists of drawing commands, and handing the result to a compositor that can move it around without asking the main thread. Then the question the whole subject turns on: when you change something, which of those stages has to run again? Nine lessons, each a short document or a short loop, traced frame by frame. A classic script in the middle of the body blocks the tokenizer while a deferred one does not; a stylesheet in the head does not block parsing but does block first paint, measured at 448 ms against a 12 ms control; a node with display:none is absent from the render tree while visibility:hidden is present and costs the same layout; a width change re-runs style, layout and paint, a background-color change re-runs style and paint but not layout, and a transform re-runs neither — 59 Layout events against 0 against 1, counted in a real Chrome trace; a loop that reads offsetWidth between writes runs 1,000 layouts and 224.5 ms where the batched version runs two and 0.8 ms; and a CSS transform animation keeps moving at 60 fps through a three-second main-thread block while the same motion written as `left` freezes solid. Every lesson also says why the pipeline is built that way, what the rule costs you in code you will actually write, defines every word it leans on where it uses it, and cites the specification clause or the captured trace behind each claim. Where a claim is Chrome-specific it says which Chrome; where the specification does not define a term that everybody uses — 'reflow' and 'layout' are both engine jargon, not spec vocabulary — it says that too.

Built with
  • react
  • tailwind
  • motion
Related

Built by Ananda Rizki, a software engineer and designer, one of the small web apps he writes for fun.

Explore more apps on Labs