Track 02 · Lesson 12 of 17Inside the browser
- 01Events and bubbling
- 02What fires when you click or type
- 03Keyboard, input and focus events
- 04Default actions and preventDefault()
- 05Event delegation
- 06Listener options and cleanup
- 07Custom events
- 08Debounce and throttle
- 09Events in React
- 10The event loop
- 11Don't block the main thread
- 12The rendering pipeline
- 13Core Web Vitals
- 14HTTP caching
- 15Responsive design
- 16SEO basics
- 17Service workers and offline
The rendering pipeline
Lesson 12 of 17· 6 min
To draw a frame, the browser works out styles, then layout (sizes and positions), then paint (pixels), then composites the layers together. Changing a CSS property restarts the pipeline from a different stage. Pick a property to see how much work it causes.
What does each change cost?
Pick a property, then animate it
- DOM
- CSSOM
- Style (runs)
- Layout
- Paint
- Composite (runs)
Work per frame
Changing transform runs Style → Composite. The element is moved as a finished layer, often by the GPU. No layout, no paint. DOM and CSSOM are built when the page loads; they only rebuild when you change the HTML or stylesheets.
/* Cheap to animate */
.box {
transition: transform 0.6s ease;
}
.box.moved {
transform: translateX(220px) rotate(20deg);
}The stages#
- Style: work out which CSS rules apply to each element.
- Layout: work out every element's size and position. Change one element's size and its neighbors may move too.
- Paint: fill in the pixels: text, colors, borders, shadows, images.
- Composite: stack the painted layers in the right order and show them. This step is often done by the GPU.
A change only restarts the pipeline from the first stage it affects. Change a width and everything runs again. Change a color and layout is skipped. Change a transform or opacity and the browser can go straight to compositing.
Layout thrashing#
Reading a layout value, like offsetHeight or getBoundingClientRect(), forces the browser to finish layout first. Write a style, read a size, write again, read again, all in a loop, and the browser has to lay out the page on every iteration. Batch your reads, then your writes.
Check yourself