CSS & Rendering Pipeline — Performance

Every visual change goes through Style → Layout → Paint → Composite, and a step that runs sets off every step after it. Geometry properties (width, height…

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:

  1. Style. The browser matches selectors and works out the final style (the computed style) of every element the change touches.
  2. 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.
  3. Paint. The browser fills in pixels: text, colours, borders, shadows, images. The result can be split across several layers.
  4. 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);
}

Why Layout costs the most

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

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.

What you will learn