CSS Reference ยท Transforms, Transitions and Animations
The will-change property
Reference for the CSS will-change property: what the hint does, why overusing it hurts performance, and its side effect of creating stacking contexts, with a demo.
The will-change property tells the browser that an element's property is about to change, so it can prepare, for example by promoting the element to its own layer. It is a performance hint, not a style: it changes nothing visually by itself.
It is easy to misuse. Applied broadly or left on permanently, it uses extra memory and can make a page slower. Treat it as a last resort after you have measured a real problem.
.drawer.is-opening { will-change: transform; }
Try it
Tag A sits in the top-left corner of the viewport, as fixed elements do. Tag B ends up inside box B, because will-change: transform makes the box the containing block for its fixed descendants, exactly as an actual transform would.
Syntax
will-change: auto | <animateable-feature>#
<animateable-feature> = scroll-position | contents | <custom-ident>
- Initial value:
auto - Applies to: all elements
- Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
auto |
No hint. The browser does its usual optimizations. |
scroll-position |
The element's scroll position will change soon. |
contents |
The element's content will change. Not useful in most pages. |
<custom-ident> |
A property name, such as transform, opacity or left. Several can be listed with commas. |
Usage notes
- It can change rendering. If you name a property that would create a stacking context or a containing block (such as
transform,opacitybelow 1,filterorposition),will-changecreates it right away. That affectsz-indexorder andposition: fixedorabsolutedescendants, as the example shows. - Do not apply it everywhere. A rule like
* { will-change: transform; }wastes memory and defeats the browser's own heuristics. - Add it shortly before the change and remove it afterwards. For example, set it in a
:hoverrule of a container, or with a script just before a long animation starts, then clear it when the animation ends. - It is not needed for most transitions. Browsers already optimize
transformandopacityanimations. Reach forwill-changeonly after profiling shows dropped frames. - Property names, not values. Write
will-change: transform, notwill-change: translateX(10px). Namingwill-changeitself, orall, is invalid. - Do not rely on it for correctness. Browsers may ignore the hint.
- Memory on mobile. Each promoted layer costs graphics memory, which is scarce on phones.
Browser support
Supported in every current browser. Browsers may ignore the hint because it is only an optimization.