Animation performance
Why some CSS animations stay smooth while others stutter, how style, layout, paint and composite set the cost, and how to measure it in DevTools.
Animation performance
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- Every frame the browser may redo up to four steps: style, layout, paint, composite. An animation is cheap when it only needs the last one.
- `transform` (including `translate`, `scale` and `rotate`) and `opacity` can usually be animated at the composite step, on a separate thread from the one running your JavaScript. That is why they keep moving when the page is busy.
- Animating `width`, `height`, `top`, `left`, `margin` or `padding` invalidates layout, so the browser recomputes geometry for the element and often its neighbours on every frame.
- Smooth means finishing each frame inside the budget: about 16.7 ms at 60 Hz and about 8.3 ms at 120 Hz.
- Do not trust a rule of thumb alone. Turn on Paint flashing and record a Performance trace to see which frames did layout and paint.
Smooth is a deadline
A screen refreshes 60 times a second on many devices and 120 or more on others. To look smooth, the browser has to hand over a new picture before each refresh. At 60 Hz that is about 16.7 milliseconds per frame, and if one frame arrives late the eye sees a hitch.
So “is this animation expensive?” really means “how much work do I make the browser redo in each of those 16.7 ms?” The answer depends on which part of the rendering pipeline each changing property touches.
The four steps
The frontend roadmap’s how browsers render a page lesson covers the whole pipeline. For animation the useful version is:
- Style: work out which rules apply and the computed values.
- Layout: work out the size and position of every affected box.
- Paint: draw each element’s pixels (colours, text, borders, shadows) into layers.
- Composite: stack the layers in the right order, applying transforms and opacity, and send the result to the screen.
A change to a property triggers the earliest step it needs and everything after it. Change width and you pay for layout, paint and composite. Change background-color and you pay for paint and composite, since no geometry moved. Change transform or opacity and, when the element is on its own layer, you pay only for composite.
Think of a stack of transparent sheets on a light table. Sliding a sheet or fading it is trivial. Redrawing the artwork on a sheet is more work. Redrawing the artwork and re-measuring where every other drawing sits is the most work.
Why transform and opacity are special
Moving something with transform does not change where it sits in the layout. Its neighbours stay put and the browser already knows how the element looks, so it can just shift the finished layer. opacity works the same way: it blends a finished layer with what is under it.
This also means the compositor thread can do the animation without involving the main thread, which is busy with your JavaScript and other layout. In practice, this is the difference between a loading spinner that keeps spinning while a big script runs and one that freezes. Browsers treat the individual translate, scale and rotate properties like transform for this purpose, and filter can also run on the compositor, though a large blur still costs a lot to compute.
Compare these two slide-ins:
/* Recomputes layout on every frame */
@keyframes slide-bad { from { left: -300px; } to { left: 0; } }
/* Moves a finished layer */
@keyframes slide-good { from { translate: -300px 0; } to { translate: 0 0; } }
The element ends in the same place. Only one of them made the browser redo layout 60 times a second.
will-change, with care
will-change: transform tells the browser to prepare a separate layer in advance. That can remove a small hitch at the start of an animation, but each layer uses memory, and a page full of promoted elements can get slower. Treat it as a scalpel: add it right before a known animation (for example on :hover of a container, so it is ready when its child moves), and remove it afterwards. Blanket * { will-change: transform } is a classic mistake.
Measure instead of guess
Rules of thumb tell you where to look. DevTools tells you what is true. In Chrome:
- Rendering tab, Paint flashing: areas that are repainted flash green. A transform animation should not flash at all, while an animation of
box-shadoworbackgroundwill. - Performance panel: record while the animation runs and look at the frames chart. Long tasks, a lot of purple (layout) or green (paint) in each frame, and dropped frames are visible.
- Animations panel: slows animations down and lets you scrub them, which is also useful for design.
The debugging with DevTools lesson is a wider tour of these panels.
Smaller habits that add up
- Animate small areas. A repaint of a 40 px icon is cheaper than a repaint of a full-width hero.
- Avoid animating layout-affecting properties on elements with many descendants.
- Keep shadows and large blurs out of continuous animations. If you need a glowing effect, animate the
opacityof a pseudo-element that already has the shadow. - Prefer one short, purposeful animation to a handful of infinite ones. Besides performance, reduced-motion users will thank you.
- If a height or width change is unavoidable, accept the layout cost but animate only that one element, and do not do it in a scrolling list.
What the video covers
Web Dev Simplified’s “How To Create Performant CSS Animations” (October 2020, about 12 minutes) lists in its description: how the browser renders CSS, how to optimise CSS animations, how to use Chrome DevTools to test them, and which properties to animate. Chrome’s DevTools interface has been reorganised since 2020, so a panel may sit in a different place than on screen. I could not read a transcript, so details beyond that list are not described here. Bramus’s Google I/O 2025 talk in further viewing covers newer features such as @starting-style and view transitions.
Where this fits
This ties back to transitions and keyframe animations: the animation you write is only half the question, the property you animate is the other half. The same pipeline thinking applies to the wider page in CSS performance and to loading metrics in web performance and Core Web Vitals.
Check yourself
You animate a menu sliding in with `left: -300px` to `left: 0`. What work does the browser repeat every frame, and what would you change?
`left` changes the element's geometry, so every frame the browser recalculates layout and then repaints. Moving it with `translate: -300px 0` to `0 0` leaves layout alone, and the animation can run at the composite step. The element ends in the same place.
Why does a `transform` animation keep running smoothly while JavaScript is busy for 200 ms, when an animation of `top` would stall?
The main thread runs JavaScript, style, layout and paint. A compositor-friendly animation has already been rasterised into a layer, and the compositor thread just moves or fades that layer on the GPU, so it does not wait for the main thread. An animation of `top` needs the main thread every frame.
Is it a good idea to put `will-change: transform` on every element so everything is fast?
No. It asks the browser to promote the element to its own layer ahead of time, and every layer costs memory. Use it on a specific element shortly before it animates, or only on elements that do animate often, and remove it when the animation is finished.
What is the frame budget at 60 Hz, and why is the real budget for your code smaller?
1000 ms divided by 60 is about 16.7 ms. The browser needs part of that time for its own work (compositing, input, the rest of the pipeline), so your own scripting and layout have noticeably less than 16.7 ms to fit in.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.