Course contentsShow
← React
Lesson 2019 of 2,39645. AnimationsFree lesson

will-change CSS Property

Use will-change to hint the browser to optimize specific properties, and understand when it backfires.

will-change CSS Property

You'll learn how to hint the browser to optimize specific properties for animations, and why overuse can hurt performance.

What is will-change?

will-change is a CSS property that tells the browser in advance which properties you plan to animate. Think of it like calling ahead to a restaurant: "I'm bringing a party of 10, please prepare a table." The browser can pre-optimize rendering layers for smoother animations.

It's especially powerful for compositor-only properties like transform and opacity, which you just learned can animate without triggering layout or paint.

The Basic Syntax

.animated-element {
  will-change: transform, opacity;
}

Or in React:

<motion.div
  style={{ willChange: 'transform' }}
  animate={{ x: 100 }}
/>

When to Use It

  • Complex animations where you notice jank
  • Before the animation starts (not during)
  • Remove it after animating to free up resources

When It Backfires

Here's the trap: will-change creates a new rendering layer, which uses memory. If you apply it to dozens of elements simultaneously, you'll consume more memory than you save in performance.

// BAD: Every card gets its own layer upfront
<div style={{ willChange: 'transform' }}>Card 1</div>
<div style={{ willChange: 'transform' }}>Card 2</div>
// ...100 more cards

Better: Apply it only on hover or just before animating, then remove it.

const [isHovering, setIsHovering] = useState(false);

<div
  style={{ willChange: isHovering ? 'transform' : 'auto' }}
  onMouseEnter={() => setIsHovering(true)}
/>

Key Takeaway: will-change is a performance hint, not a performance guarantee—use it sparingly, only for properties you're actually about to animate, and remove it when done.