Animation Performance: The Rendering Pipeline, Compositing and will-change
Why some animations stutter: the style, layout, paint and composite steps, which properties trigger which, transform and opacity on the compositor, will-change and its side effects, contain, the FLIP technique, and measuring with developer tools.
kvi5hnuCode Sprout team member8 min readOn this page
Smooth motion means a new frame every 16.7ms at 60 frames per second, or 8.3ms on a 120Hz screen. If the browser can't produce frames that fast, the animation janks: it stutters or skips. Which CSS properties you animate makes the biggest difference.
The rendering pipeline

For every frame where something changed, the browser may run four steps:
- Style: work out which rules match and compute each element's values.
- Layout: calculate every box's size and position. A change to one box's size can move many others.
- Paint: draw text, colors, borders, shadows and images into one or more layers.
- Composite: combine the layers, moved and blended, into the final image, usually on the GPU.
An animation is cheap or expensive depending on the first step it forces:
| Animating | Runs | Cost |
|---|---|---|
width, height, margin, padding, top, left, font-size, border-width | layout, paint, composite | highest; affects other elements |
color, background-color, box-shadow, border-radius, outline | paint, composite | medium; grows with the painted area |
transform, translate, rotate, scale, opacity | composite only | lowest |
So animate transform and opacity whenever you can:
- Move with
translateinstead oftopandleft. - Resize with
scaleinstead ofwidthandheight, where distorting the content briefly is acceptable. - Fade with
opacityinstead of changing colors.
filter can often be composited too, though large blurs are expensive.
The compositor
Browsers can put an element on its own compositor layer, a separately painted image the GPU can move, scale and fade without repainting. Transform and opacity animations on such layers run on the compositor thread, separate from the main thread where JavaScript, style and layout run.
So a compositor animation keeps running smoothly while JavaScript is busy. A layout or paint animation freezes whenever the main thread is blocked. The playground below shows the difference.
Layers cost memory, especially large ones on high-density screens, and too many slow the composite step. Browsers create them automatically when transform or opacity animations start.
will-change
will-change tells the browser in advance that a property is about to change, so it can prepare, typically by creating a layer before the animation starts. That avoids a stutter on the first frame:
.drawer { will-change: translate; }
.drawer.open { translate: 0 0; }
| Value | Meaning |
|---|---|
auto (default) | no hint |
property names, like transform, opacity | those properties will change |
scroll-position | the element's scroll position will change |
contents | the element's contents will change |
will-change has side effects. If the named property would create a stacking context or a containing block when set, will-change creates it now. Tested in Chrome, a position: fixed child was placed relative to its parent, instead of the viewport, when the parent had will-change: transform or will-change: filter, but not opacity. will-change: opacity still creates a stacking context.
Use it sparingly:
- Don't apply it to many elements, or "just in case":
* { will-change: transform }wastes memory and can make things slower. - Apply it shortly before a change, for example on hover of a parent or from JavaScript, and remove it afterward. Leaving it on long-running elements is fine for things that animate constantly.
- Use it to fix a measured problem, not as a default.
The old hack of transform: translateZ(0) to force a layer is replaced by will-change: transform.
Containment: contain
contain promises the browser that an element's inside doesn't affect the outside, so it can limit layout and paint work to that element:
| Value | Promise |
|---|---|
layout | nothing inside affects layout outside; the element becomes a containing block and a stacking context |
paint | nothing inside is drawn outside its box; content is clipped like overflow: clip |
size | its size doesn't depend on its children; give it a size, or it collapses |
inline-size | as size, for the inline axis only |
style | counters and quotes don't escape |
content | layout paint style |
strict | size layout paint style |
Tested in Chrome: a box with contain: size and a paragraph inside was 0px tall, and a box with contain: layout became the containing block of its fixed-position child.
contain: content is a safe choice for independent widgets like cards, comments or ads, whose changes shouldn't trigger layout elsewhere. container-type (article 78) applies size or inline-size containment, and content-visibility: auto (article 46) applies containment and skips rendering off-screen content.

The last two panels differ only in the property named in will-change: transform would create a containing block, so the hint creates one now; opacity wouldn't, so the fixed badge escapes.
Avoiding forced layout in JavaScript
Reading layout values like offsetHeight, getBoundingClientRect() or scrollTop right after changing styles forces the browser to run layout immediately. Alternating reads and writes in a loop, called layout thrashing, can run layout hundreds of times in one frame:
// slow: each read forces a layout because of the previous write
for (const el of items) el.style.height = el.parentNode.offsetHeight / 2 + 'px';
// fast: read everything first, then write
const heights = items.map(el => el.parentNode.offsetHeight);
items.forEach((el, i) => el.style.height = heights[i] / 2 + 'px');
For JavaScript-driven animation, use requestAnimationFrame() or the Web Animations API (element.animate()), which can also run on the compositor.
FLIP: animating layout changes cheaply
When an element must move to a new place in the layout, such as items reordering in a list, the FLIP technique animates it with transform:
- First: record its position with
getBoundingClientRect(). - Last: make the layout change, and record the new position.
- Invert: apply a
translate(andscale) that puts it back at the first position. - Play: animate that transform back to none.
const first = el.getBoundingClientRect();
list.prepend(el); // the layout change
const last = el.getBoundingClientRect();
el.animate([
{ translate: `${first.left - last.left}px ${first.top - last.top}px` },
{ translate: '0 0' }
], { duration: 300, easing: 'ease-out' });
View transitions (article 114) automate this for whole-page or component state changes.
Measuring
- The Performance panel in Chrome and Edge, and the equivalents in Firefox and Safari, record frames and show time spent in style, layout, paint and scripting. Long purple (layout) or green (paint) bars during an animation point to the culprit.
- Rendering tools: "Paint flashing" highlights repainted areas, "Layer borders" shows compositor layers, and the frame rendering stats show the frame rate.
- Test on slow devices: use CPU throttling, 4× or 6× slower, since a fast laptop hides problems.
- Interaction to Next Paint (INP), a Core Web Vital, measures how quickly the page responds visually to input, which heavy style and layout work delays.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
.lane { position: relative; block-size: 2.4rem; margin-block: 0.4rem; border-block-end: 1px dashed #d8cfc0; container-type: inline-size; }
.box {
position: absolute; inset-block-start: 0.2rem; inline-size: 5.5rem; padding: 0.4rem 0; text-align: center;
border-radius: 6px; color: white; font-weight: 700;
}
.left { background: #c0392b; animation: by-left 1.6s ease-in-out infinite alternate; }
.tr { background: #2f7d32; animation: by-translate 1.6s ease-in-out infinite alternate; }
@keyframes by-left { from { left: 0; } to { left: calc(100cqi - 5.5rem); } } /* layout every frame */
@keyframes by-translate { from { translate: 0; } to { translate: calc(100cqi - 5.5rem); } } /* composite only */
button { font: inherit; padding: 0.4rem 0.8rem; }
.note { color: #555; min-block-size: 1lh; }
@media (prefers-reduced-motion: reduce) { .box { animation-duration: 6s; } }
While the main thread is blocked, the red box, animated with left, freezes because each frame needs layout, while the green box, animated with translate, keeps moving. In browsers that don't run that animation on the compositor, both freeze.
What's current
- Compositor animation of
transform,opacityand the individual transform properties: all major browsers. will-changeandcontain: all browsers.
Common questions
Why does my animation stutter?
It probably animates a layout or paint property. Switch to transform or opacity, and check the Performance panel.
Should I add will-change: transform to everything?
No. It uses memory, has side effects, and only helps where you've measured a problem.
How do I animate an element's size smoothly?
Animate scale, or use FLIP. If the content must reflow, animating width or height may be unavoidable; keep the affected area small with contain.
Does transform affect layout?
No, which is exactly why it's cheap.
Summary
- Frames go through style, layout, paint and composite; animate properties that skip the expensive steps.
transformandopacitycan run on the compositor, which stays smooth even when JavaScript is busy.will-changecreates layers ahead of time, but creates stacking contexts and containing blocks too; use it sparingly.containlimits the reach of layout and paint work.- Batch layout reads before writes, use FLIP for layout changes, and measure on slow devices.
Practice questions
Rewrite this hover effect so it doesn't trigger layout.
.card { position: relative; top: 0; transition: top 0.2s; }
.card:hover { top: -4px; }
Answer
.card { transition: translate 0.2s; }
.card:hover { translate: 0 -4px; }
A fixed-position tooltip inside a drawer is suddenly positioned relative to the drawer instead of the viewport, after someone added will-change: transform to the drawer. Why?
Answer
will-change: transform makes the drawer a containing block for fixed-position descendants, as transform itself would. Remove will-change, add it only during the animation, or move the tooltip outside the drawer, for example into the top layer.
A shadow grows on hover with transition: box-shadow 0.3s, and it stutters on a large card. What's a cheaper way?
Answer
Put the larger shadow on a pseudo-element and fade it in with opacity, which only needs compositing:
.card { position: relative; }
.card::after { content: ""; position: absolute; inset: 0; border-radius: inherit; box-shadow: 0 12px 32px rgb(0 0 0 / 0.25); opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.card:hover::after { opacity: 1; }
What does contain: content promise, and where is it useful?
Answer
It's layout paint style: the element's contents don't affect layout outside it, aren't painted outside its box, and don't leak counters. It suits independent widgets like cards, comments and embeds, so changes inside them don't make the browser re-lay out the rest of the page.
Previous: Animation in Depth: Fill Modes, Direction, Composition, Events and Interruptions
Next: Accessible Motion: prefers-reduced-motion and Meaningful Animation

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.