CSS Animations That Don't Kill Performance

Create smooth 60fps CSS animations using transform, opacity, and will-change. Learn which properties to animate and which to avoid.

· 3 min read

Abstract long exposure light trails in vibrant shades of blue, pink, and orange
In this article7 sections
  1. Why Most CSS Animations Are Slow
  2. The Golden Rule: Only Animate Composited Properties
  3. Will-Change: The Performance Hint
  4. Animation Timing Functions
  5. Reducing Motion for Accessibility
  6. Measuring Animation Performance
  7. Common Patterns Done Right

Why Most CSS Animations Are Slow

Not all CSS properties are created equal when it comes to animation performance. Animating width, height, margin, padding, or top/left forces the browser to recalculate layout, repaint, and composite on every frame. At 60fps, that is 16.67 milliseconds per frame, which is not enough time for layout recalculation on complex pages.

The Golden Rule: Only Animate Composited Properties

The only properties you should animate are transform and opacity. These properties can be handled entirely by the GPU compositor without triggering layout or paint operations. The browser creates a separate layer for the element and moves or fades it independently.

Transform Covers Most Use Cases

  • Movement: translate(x, y) instead of top/left
  • Scaling: scale() instead of width/height
  • Rotation: rotate() for spinning effects
  • 3D effects: perspective(), rotateX(), rotateY()

Opacity for Visibility

Use opacity for fade-in and fade-out effects instead of visibility or display. Opacity transitions are GPU-accelerated and buttery smooth even on mobile devices.

Will-Change: The Performance Hint

The will-change CSS property tells the browser that an element is about to animate, allowing it to set up GPU layers ahead of time. Use it sparingly: will-change: transform on elements you are about to animate. Remove it after the animation completes.

Do not set will-change on too many elements. Each element with will-change gets its own GPU layer, consuming video memory. On mobile devices with limited GPU RAM, too many layers actually hurt performance.

Animation Timing Functions

The default ease timing function works for most animations, but custom cubic-bezier curves can make animations feel more natural. Use ease-out for elements entering the screen (fast start, slow end) and ease-in for elements leaving (slow start, fast end).

For spring-like physics effects, use a cubic-bezier with values that overshoot: cubic-bezier(0.34, 1.56, 0.64, 1) creates a subtle bounce at the end.

Reducing Motion for Accessibility

Always respect the prefers-reduced-motion media query. Users who enable reduced motion in their OS settings may have vestibular disorders that make animations nauseating. Wrap your animations in a media query that disables or simplifies them when reduced motion is preferred.

Measuring Animation Performance

Open Chrome DevTools, go to the Performance tab, and record while your animation plays. Look at the Frames section for dropped frames and the Main section for long tasks during the animation. The Rendering tab has options to show paint flashing and layer borders that help visualize what the browser is doing.

Common Patterns Done Right

A card hover effect should use transform: translateY(-4px) and box-shadow transition rather than changing padding or margin. A modal entrance should use transform: scale(0.95) to scale(1) with opacity: 0 to 1, not height: 0 to auto. A sidebar toggle should use transform: translateX(-100%) rather than width: 0 or left: -300px.

  • CSS
  • Animation
  • Performance

Written by Pontus Henriksson

Co-founder and CEO of Walldy in Sundsvall. I have built for the web since I was fourteen, tested games for studios like Netflix and Bungie since 2021, and write about what I use in real projects.

Liked this? Get the next one.

New Claude skills, kits and what I learn building AI for small businesses. Not often, only when it is worth sending. Unsubscribe with one click.

Tools for this.

Claude skills, kits and guides that put ideas like these to work. Many are free with an account.

Visit the shop