The will-change Property
What you'll learn: How to give the browser a heads-up about which properties will animate, so it can optimize rendering performance ahead of time.
What is will-change?
The will-change property tells the browser which CSS properties you're planning to animate or change soon. Think of it as a courtesy call—by knowing what's coming, the browser can prepare the rendering layers in advance, making your animations smoother.
Imagine you're about to move furniture. If you tell someone beforehand, they can clear the path and help prep. Without warning, things get messy and slow. will-change gives the browser that warning.
How to Use will-change
You specify which property (or properties) will change:
.box {
will-change: transform;
}
This tells the browser: "Hey, I'm going to animate the transform property on this element soon."
You can also hint at multiple properties:
.card {
will-change: transform, opacity;
}
Important Considerations
Don't overuse it! Applying will-change to every element or leaving it on permanently wastes memory. The browser creates optimized layers that consume resources. Use it only when needed, and remove it after the animation:
.button:hover {
will-change: transform;
}
Or add/remove it via JavaScript before and after animations.
Common properties to hint: transform, opacity, filter—those that benefit from compositor-only rendering (as you learned in the previous lesson on composite-only animations).
Key Takeaway:
Use will-change sparingly to hint the browser about upcoming animations, enabling performance optimizations—but remove it when not needed to avoid wasting resources.