CSS rendering: layers, threads, and why transform beats width

2025/09/21
frontendbrowsercssperformance

To make a side menu slide in from the left, there are two ways to draw it: grow its width from 0 to 240px, or keep it 240px wide the whole time and move it in from off-screen with transform. On screen they look identical, yet the width one can stutter while the transform one stays smooth. Why the difference?

Below, the left side slides with width and the right side with transform. With just "Slide in", the two look the same. "Slide in while JavaScript runs for 600ms" starts the slide and then has JavaScript hold the main thread for 600ms in one go. The whole page freezes for that time, scrolling included, and only the right sidebar keeps sliding.


The rendering waterfall

The browser turns CSS into pixels in stages. Each stage feeds the next. Triggering an early stage forces everything after it to re-run.

Style → Layout → Paint → Composite

  • Style works out which CSS rules apply to each element.
  • Layout computes each element's size and position.
  • Paint works out the pixels of each layer, a part of the page drawn as its own image.
  • Composite stacks the layers into the final image.

Style, Layout, and Paint run on the Main Thread, the same thread that runs JavaScript. Composite runs on a separate Compositor Thread, and the GPU draws the result.

A screen that refreshes 60 times a second needs a new image every 16.7ms (1000 ÷ 60). If JavaScript, Style, Layout, and Paint on the Main Thread take longer than that together, the frame misses its refresh, the screen keeps showing the previous image, and the animation visibly hitches. The Compositor Thread also has to deliver an image every 16.7ms, but it runs no JavaScript, so while JavaScript holds the Main Thread, an animation the Compositor Thread can finish on its own keeps moving.

Change width? The browser recalculates Layout, repaints pixels, re-composites layers. Layout and Paint both run on the Main Thread, so every frame shares those 16.7ms with JavaScript.

Change color? Layout stays the same, but it still has to repaint. Paint is on the Main Thread too, so when JavaScript stalls, a color animation stops as well.

Change transform? Layout and Paint don't re-run. Only Composite does, and the whole thing finishes on the Compositor Thread without sharing time with JavaScript. Tested in November 2026 on Chrome 153: while a busy loop held the Main Thread for 600ms, the transform transition drew 36 frames and the width transition drew none.


Which properties trigger what

TriggerPropertiesWhat happens
Layoutwidth, height, margin, padding, top, left, font-sizeRecalculates positions of surrounding elements. Expensive.
Paintcolor, background, border-color, box-shadow, outlineRedraws pixels. Positions stay the same.
Compositetransform, opacity, filter (except blur() and drop-shadow())Re-composites layers on the GPU. Cheap.

blur() and drop-shadow() spread pixels outside the element, so Chrome animates them on the Main Thread. Chrome 153 animates background-color on the Compositor Thread, despite the Paint row.

Each row below is one property. If you press "Animate all while JavaScript runs for 600ms", the Main Thread is held for 600ms halfway through the animation. During that time the rows that need the Main Thread stop, and only the ones running on the Compositor Thread keep moving:

For animations, always pick the Composite version:

Instead ofUse
left / top / margintransform: translateX/Y()
width / heighttransform: scale() (stretches the content)
display: none/blockopacity: 0/1 (still takes space and clicks)

Compositor layers

A transform animation can skip Paint because, during the animation, the element is promoted to its own layer: its pixels are painted once, and each frame only moves that image. Each layer takes GPU memory; for example, the layer of a 500x500 element takes roughly 1MB (4 bytes per pixel). So the browser promotes elements to independent Compositor layers only when it has a reason to.

What creates a layer:

  • 3D transforms. translateZ(0) and translate3d() trigger layer promotion immediately. 2D transforms like translateX(50px) usually don't, unless they're inside an active animation.
  • will-change: transform. Forces the browser to create a layer in advance. Use it on elements you know will animate. Remove it after. Keeping layers alive wastes memory.
  • position: fixed. Fixed elements get their own layer.
  • Active transform or opacity animations. Even 2D transforms temporarily get a layer during animation. The browser promotes them for the duration, then demotes them when it ends.

What doesn't create a layer:

  • Hover states. Hover itself has nothing to do with layers. A color change on hover stays on the Main Thread. Only the animation triggered by hover might create one.
  • Static transform. transform: translateX(50px) without animation or will-change is painted along with the rest of the page. No layer promotion.

What this looks like in practice

A sidebar that slides in. Two ways to build it.

/* Animating width: Layout reflow every frame */
.sidebar {
  width: 0;
  transition: width 0.3s;
}
.sidebar.open {
  width: 240px;
}

A recording in the DevTools Performance panel shows Layout and Paint in every frame. With a data table on the page, each Layout also recalculates the table's column widths. Tested in November 2026 on Chrome 153, with a 125-row table next to the sidebar: about 2.7ms of Main Thread work per frame at full CPU speed, and about 13.1ms with DevTools CPU throttling set to 6x slower. That is 80% of a 16.7ms frame, but every run, at both speeds, still drew 61 or 62 frames a second. So in this test, the Main Thread work a width animation needs per frame stayed under 16.7ms. With JavaScript running at the same time, the two together can go over. The embed at the top runs JavaScript for 600ms straight; during that time the Main Thread can't produce a single frame, so the width sidebar stops completely.

/* Animating transform: Compositor only */
.sidebar {
  width: 240px;
  transform: translateX(-100%);
  transition: transform 0.3s;
}
.sidebar.open {
  transform: translateX(0);
}

The Performance panel shows no Layout at all. The sidebar has its own layer during the transition. The Main Thread handles only the first and last few frames. The Compositor Thread draws the rest.

The sidebar is always 240px wide. It just starts off-screen and slides in. Same visual result. No reflow.


The will-change trap

Developers discovered will-change and slapped it on everything.

/* Don't do this */
* { will-change: transform, opacity; }

Each will-change creates a layer: in Chrome 153, a page with 200 divs went from 4 layers to 207. At 1MB per 500x500 element, 200 elements that size need about 200MB. web.dev warns that on devices with limited memory, that many layers can cost more than they gain.

Use will-change like a scalpel:

/* Add it right before animation */
.card {
  transition: transform 0.1s;
}
.card:hover {
  will-change: transform;
}
.card:active {
  transform: scale(0.98);
}

The transition goes on .card, not .card:active. Otherwise the card snaps back when the mouse is released. In the two cards below, the left one is written as above and the right one only has the transition inside :active. To make it easy to follow, the transition is stretched to 1s and the card shrinks to half:

Most of the time you don't need will-change at all: the browser auto-promotes elements during a transform or opacity transition or animation. You only need will-change when you want the layer created before the animation starts, to avoid a first-frame hitch.


Quick checklist

  1. Animate transform and opacity. These two run on the Compositor Thread.
  2. Use will-change on one or two elements, not globally. Remove it after animation ends.
  3. Record the animation in the DevTools Performance panel. If the Main track (the Main Thread's row) shows work in every frame, the animation is not on the Compositor Thread, even with no Layout or Paint in it.
  4. Test on slow hardware, or with DevTools CPU throttling. A fast laptop hides Layout cost.

References