Hover over a button and its colour changes. Hover over a card and it gets wider. To you, both are small changes. To the browser, the second can mean working out the position of every element next to it again.
Every time something on the page changes how it looks, say a button is hovered, JavaScript adds a class, or an animation runs, the browser runs its drawing steps again. Those steps are called the rendering pipeline: Style, Layout, Paint, Composite. Picture a class notice board. If one sheet is made wider, every sheet next to it has to be moved and rearranged. If only the colour of the writing on one sheet changes, you just rewrite that sheet. If the sheet is stuck on a clear plastic film, you can slide the film around without rewriting anything. The CSS property you change decides which work has to be done again.
Four steps, always in order
In the Critical Rendering Path lesson you saw these steps when the page first opens. Once the page is showing, every change goes down the same path:
- Style. The browser matches selectors and works out the final style (the computed style) of every element the change touches.
- Layout. The browser works out the position and size of every element. When one element gets wider, its neighbours, its parent and its children are worked out again too. This step is also called reflow.
- Paint. The browser fills in pixels: text, colours, borders, shadows, images. The result can be split across several layers.
- Composite. Those layers are stacked into the one picture on the screen. The GPU helps with this, and it can run off the main thread.
In front of it there's usually JavaScript (or a hover, or a CSS animation) that sets off the change. The order is always Style → Layout → Paint → Composite. A step that runs sets off every step after it: if Layout runs, Paint and Composite always follow. The only thing that can happen is skipping steps in the middle.
Which property triggers which step
| What changes | Steps that run | Example properties |
|---|---|---|
| Size or position (geometry) | Style → Layout → Paint → Composite | width, height, margin, padding, top, left, font-size, display |
| Looks only | Style → Paint → Composite | color, background-color, box-shadow, border-color, visibility |
| Layer only | Style → Composite | transform, opacity |
So a button that changes its background-color on hover skips Layout. The button's size doesn't change, so the position of other elements doesn't need working out again. The button's pixels still have to be repainted.
transform and opacity only need Composite when the element already has its own layer. The browser usually makes that layer for you while a transform or opacity animation runs.
The Lab's example: one card, two neighbours
The Lab has three cards in a row, each 72 px wide. Only the middle card changes.
| Change on the middle card | Do its neighbours move? | Steps that run |
|---|---|---|
width: 72px to 108px |
yes, the right card is pushed 36 px | Style, Layout, Paint, Composite |
background-color blue to orange |
no | Style, Paint, Composite |
transform: scale(1.5) |
no, the card looks bigger and overlaps its neighbours, its own space stays the same | Style, Composite |
width: 108px and scale(1.5) both make the card look 108 px wide. The difference: width changes geometry, so the browser has to work out where the right card goes again. transform only enlarges the finished picture of the card, without touching layout.
/* Expensive: every frame of the transition runs Layout */
.card {
width: 72px;
transition: width 0.3s;
}
.card:hover {
width: 108px;
}
/* Cheap: it looks bigger, Composite only */
.card-lean {
transition: transform 0.3s;
}
.card-lean:hover {
transform: scale(1.5);
}
transition: width 0.3sanimateswidthover 0.3 seconds. On a 60 Hz screen that's about 18 frames, and every frame runs Layout, Paint and Composite.transform: scale(1.5)enlarges it 1.5 times from the centre. Its layout stays 72 px, so the neighbours don't move.transition: transform 0.3sonly needs Composite on each frame.
Why Layout costs the most
- Layout spreads. One element changing size can move everything beside and below it. On a page with thousands of elements, there's a lot to work out.
- Paint grows with area. Repainting a small button is cheap; repainting the whole page's background or a big blurry shadow is much heavier.
- Composite only stacks finished layers. The GPU can move, scale or fade a layer without redrawing what's in it.
For a change that happens once on a click, the difference often goes unnoticed. In an animation this work repeats on every frame, so the property you pick decides whether the motion is smooth or choppy.
⚠️ Wrong guesses about which steps run
- Animating
width,height,toporleft. Every frame runs Layout. Usetransform: scale()ortransform: translate()instead. - Thinking
display: noneandvisibility: hiddenare the same.display: nonetakes the element out of the layout, so its neighbours move (Layout).visibility: hiddenonly hides its pixels and keeps its space (Paint). - Thinking a colour change is free. Layout is skipped, but Paint still runs. A big blurry shadow or a page-wide background is still expensive when changed every frame.
- Thinking the steps can come in any order. The order is always Style, Layout, Paint, Composite. Steps can be skipped, never swapped.
TL;DR: Every visual change goes through Style → Layout → Paint → Composite, and a step that runs sets off every step after it. Geometry properties (width, height, margin, padding, top, left, font-size) run all four, so changing width triggers Layout, Paint and Composite. Looks-only properties (color, background-color, box-shadow) skip Layout. transform and opacity only need Composite. In the Lab, width: 108px pushes the right card 36 px, while transform: scale(1.5) looks just as big without moving anything.
⚡ Four steps, always in order
Meaning: Every visual change goes through Style → Layout → Paint → Composite. A step that runs sets off every step after it. Steps can be skipped, never swapped.
⚡ The property decides the steps
Guess first: you change one element's width. Which steps run?
All of them: Layout, Paint and Composite. width changes geometry, so the position of its neighbours is worked out again too.
Meaning: Looks-only properties such as color, background-color and box-shadow skip Layout but still Paint. transform and opacity only need Composite.
⚡ Looking bigger without Layout
Write:
.card-lean {
transition: transform 0.3s;
}
.card-lean:hover {
transform: scale(1.5);
}
Meaning: width: 108px pushes the right card 36 px and runs Layout on every frame of the transition. transform: scale(1.5) looks just as big, but its layout stays 72 px and its neighbours don't move.