Skip to content
Tutorials Center
My learning

Topics

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.

CSS
.drawer.is-opening {
  will-change: transform;
}

Try it

A side effect you can see

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

CSS
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, opacity below 1, filter or position), will-change creates it right away. That affects z-index order and position: fixed or absolute descendants, 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 :hover rule 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 transform and opacity animations. Reach for will-change only after profiling shows dropped frames.
  • Property names, not values. Write will-change: transform, not will-change: translateX(10px). Naming will-change itself, or all, 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.