Parse, style, layout, paint, composite: the whole lesson in words
The filters drawer slides smoothly on a laptop but stutters on a mid-range phone.
Symptom
An agent built a filters drawer that slides across an orders page. On a mid-range phone, the slide stutters.
A smooth animation on a fast laptop can stutter on a phone.
Predict
Before we explain anything: the drawer moves by changing left on every frame. Which stages does the browser run each frame?
Style
Each frame starts with style. The browser works out which CSS rules apply to each element and calculates its final styles.
Style: match rules to elements, compute final styles.
Layout
Then layout. With the styles known, the browser calculates how big each box is and where it sits on the page.
Layout: the size and position of every box.
Paint
Then paint. The browser fills in the pixels: text, colours, borders, shadows. It paints onto layers, here one for the page and one for the drawer.
Paint: fill in the pixels, layer by layer.
Composite
Last, composite. The compositor puts the layers together in the right order and sends the frame to the screen. It runs on its own thread, apart from your JavaScript.
Composite: stack the layers into one frame, on the compositor thread.
Swap to transform
At sixty frames a second, all of this has about sixteen milliseconds. Now the drawer moves with transform instead of left. Which stages run?
Measured
Chrome measured both, with the processor slowed four times, like a phone. With left, layout ran 119 times and paint 236. With transform, both ran only at page load. Style still runs, because the script sets a style every frame.
transform skips layout and paint; left runs them every frame.
Break it: colour
Now animate background-color instead. The drawer does not move or resize, so layout is skipped. But new colour means new pixels: paint ran 236 times.
Colour changes skip layout but not paint.
Agent bug
Back to the agent's drawer. Moving it with left re-runs layout and paint on every frame, which a slow phone cannot fit into sixteen milliseconds. Move it with transform: translateX instead.
Animate transform and opacity, not left, top, width or height.
Recap
Every frame can run style, layout, paint and composite. A change starts at the first stage it touches: geometry at layout, colour at paint, and transform goes straight to composite.
Style → layout → paint → composite.
The common wrong idea
Any CSS change costs the same: the browser just redraws the page.
What really happens
Each frame can run style, layout, paint and composite. A change re-runs the stages from the first one it affects: left and width start at layout, colours at paint, and transform or opacity on their own layer go straight to composite.
The one-page cheatsheet for this lesson →