CSS will-change Property

The CSS will-change property provides the browser with a hint that certain properties of an element are expected to change.

Browsers can use this information to prepare rendering optimizations before a change occurs, potentially improving the smoothness of animations and other visual updates. However, unnecessary use of will-change can consume additional resources and reduce performance.

Syntax

The will-change property accepts the keyword auto or a comma-separated list of features that are expected to change.

selector {
  will-change: auto | <animateable-feature>#;
}

Common declarations include:

.element {
  will-change: transform;
}
.element {
  will-change: opacity;
}
.element {
  will-change: transform, opacity;
}
.element {
  will-change: scroll-position;
}
.element {
  will-change: contents;
}

The listed features tell the browser what may change, but they do not cause those changes themselves.

Property Values

Value Description
auto Allows the browser to perform its normal optimizations without additional hints. This is the initial value.
scroll-position Indicates that the element's scroll position is expected to change.
contents Indicates that the element's contents are expected to change, potentially allowing the browser to avoid certain caching optimizations.
<custom-ident> Names a CSS property expected to change, such as transform, opacity, or left.
initial Resets the property to its initial value, auto.
inherit Uses the computed value of the parent element.
unset Resets the property to auto because will-change is not inherited.
revert Reverts the property to the value established by an earlier cascade origin.
revert-layer Reverts the property according to the previous cascade layer.

The keywords auto, scroll-position, and contents cannot be used as CSS property names in a will-change list. The CSS-wide keywords are also reserved.

How It Works

When a browser renders a page, it performs several operations, including style calculations, layout, painting, and compositing. Some visual changes require more work than others.

The will-change property allows developers to indicate which features may change soon. Depending on the browser and the property involved, the browser may prepare an optimization ahead of time.

For example, an element that will animate using transform may benefit from compositing optimizations.

.animated-box {
  will-change: transform;
  transition: transform 0.3s ease;
}
.animated-box:hover {
  transform: translateX(40px);
}

In this example, will-change provides a performance hint. The transition and transform properties control the actual animation.

The browser is not required to perform a particular optimization. The effect depends on the browser, rendering environment, and property being changed.

Using will-change

Preparing Transform Animations

The transform value is commonly used for elements that move, rotate, or scale.

.moving-element {
  will-change: transform;
}

This hint may help the browser prepare for changes to the element's transform.

Preparing Opacity Animations

The opacity value indicates that the element's transparency is expected to change.

.fading-element {
  will-change: opacity;
}

This can be useful for elements that fade in or out frequently, although browsers already optimize many common opacity animations.

Preparing Multiple Properties

Multiple expected changes can be listed using commas.

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

Only include properties that are actually expected to change. Adding unnecessary properties may increase rendering overhead.

Preparing for Scrolling

The scroll-position keyword indicates that the element's scroll position is expected to change.

.scroll-container {
  overflow-y: auto;
  max-height: 250px;
  will-change: scroll-position;
}

This may allow the browser to prepare for scrolling-related updates. It does not make an element scrollable or automatically improve scrolling performance.

Preparing for Content Changes

The contents keyword indicates that the element's contents are expected to change.

.dynamic-content {
  will-change: contents;
}

This hint may affect how the browser caches or renders an element's contents. It should be used cautiously because disabling useful caching optimizations can make rendering slower.

Performance Considerations

The will-change property is intended as a targeted optimization tool, not a general performance improvement that should be applied to every element.

Use It Only When Necessary

Modern browsers already recognize and optimize many common animations. Adding will-change may provide no measurable improvement when the browser is already handling the animation efficiently.

Use browser performance tools to identify an actual rendering problem before introducing optimization hints.

Avoid Applying It to Many Elements

Some optimizations can require additional memory or rendering resources. Applying will-change to a large number of elements can therefore reduce overall performance.

/* Avoid broad, unnecessary hints */
* {
  will-change: transform;
}

This declaration is not recommended because it asks the browser to prepare every element for transform changes.

Apply It Shortly Before a Change

Whenever practical, enable will-change shortly before an expensive animation and remove it when the optimization is no longer needed.

.panel {
  transition: transform 0.4s ease;
}
.panel.preparing {
  will-change: transform;
}
.panel.active {
  transform: translateX(100px);
}

JavaScript can add the preparing class before the animation begins and remove it afterward. Allowing the browser some time to prepare can be more useful than enabling the hint at the exact moment the animation starts.

Understand Stacking Context Changes

Some will-change values can affect rendering behavior even before the corresponding property changes.

For example, will-change: opacity can establish a stacking context because a non-default opacity value would establish one.

This may affect how overlapping elements are painted and how z-index behaves.

Examples

Example 1: Transform Animation

The following example prepares an element for movement using transform.

.box {
  will-change: transform;
  transition: transform 0.3s ease;
}
.box:hover {
  transform: translateX(50px);
}

The browser receives the hint before the element moves. The actual movement is defined by the hover rule.

Example 2: Opacity Transition

The following example uses will-change with a fading effect.

.fade-box {
  opacity: 1;
  will-change: opacity;
  transition: opacity 0.4s ease;
}
.fade-box:hover {
  opacity: 0.4;
}

The opacity property determines transparency, while will-change only supplies a rendering hint.

Example 3: Combining Transform and Opacity

Both properties can be identified when an element is expected to move and fade.

.notification {
  will-change: transform, opacity;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.notification.hidden {
  transform: translateY(-20px);
  opacity: 0;
}

This pattern can be useful for frequently animated notifications or interface panels when performance testing shows that advance preparation is beneficial.

Example 4: Returning to Automatic Optimization

Set will-change back to auto when the hint is no longer needed.

.element {
  will-change: transform;
}
.element.finished {
  will-change: auto;
}

This allows the browser to return to its normal optimization decisions.

Inheritance

The will-change property is not inherited. A child element does not automatically receive the value specified on its parent.

.parent {
  will-change: transform;
}
.child {
  /* Computed value remains auto */
}

The initial value is auto. The property applies to all elements and has a discrete animation type.

Although the value is not inherited, rendering optimizations applied to a parent may still influence how its descendants are rendered.

Practical Example

This example demonstrates a card that moves slightly upward and changes opacity when hovered or focused. The will-change declaration provides a hint for the expected changes.

HTML

<div class="will-change-demo">
  <button class="will-change-card" type="button">
    <strong>Interactive Card</strong>
    <span>Hover or focus to see the effect.</span>
  </button>
</div>

CSS

.will-change-demo {
  display: flex;
  justify-content: center;
  padding: 20px;
}
.will-change-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: #e8f2ff;
  color: #222;
  font: inherit;
  cursor: pointer;
  opacity: 1;
  will-change: transform, opacity;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.will-change-card:hover,
.will-change-card:focus-visible {
  transform: translateY(-8px);
  opacity: 0.8;
}
@media (prefers-reduced-motion: reduce) {
  .will-change-card {
    transition: none;
  }
}
Browser Result

Result: The card moves upward and becomes slightly transparent when hovered or focused. The visible effect comes from transform, opacity, and transition. The will-change property does not create the animation.

This demonstration keeps the hint enabled so the effect can be repeated easily. In production, apply it selectively and only when performance measurements justify its use.

Common Mistakes

Expecting will-change to Animate an Element

The will-change property does not change an element's appearance or create animations.

/* Does not move the element */
.box {
  will-change: transform;
}

Use properties such as transform, transition, or animation to create the actual visual effect.

Applying will-change to Every Element

Using will-change throughout a page can waste resources and reduce performance. Limit it to elements that have demonstrated rendering problems.

Leaving Optimization Hints Enabled Indefinitely

Keeping will-change active after an animation finishes may cause the browser to retain unnecessary optimizations.

Remove the hint when it is no longer useful, particularly for expensive or infrequent animations.

Using Incorrect Value Separators

Multiple features must be separated by commas.

/* Incorrect */
.box {
  will-change: transform opacity;
}
/* Correct */
.box {
  will-change: transform, opacity;
}

Assuming Hardware Acceleration Is Guaranteed

The will-change property does not guarantee GPU acceleration, a new compositing layer, or improved performance. Browsers decide which optimizations are appropriate.

Important Considerations

  • Performance hints: The property provides advance information rather than forcing a particular rendering optimization.
  • Browser decisions: Browsers may ignore hints when an optimization is unnecessary or too expensive.
  • Memory usage: Some optimizations can increase memory consumption, particularly when applied to many elements.
  • Stacking contexts: Certain values can establish stacking contexts before the corresponding property changes.
  • Animation timing: Apply hints early enough for the browser to prepare, rather than assuming an immediate benefit.
  • Accessibility: Respect reduced-motion preferences when creating animations. The will-change property does not replace motion accessibility controls.
  • Responsive layouts: Apply hints selectively across screen sizes. Mobile devices may have tighter memory and rendering constraints.
  • Testing: Measure performance before and after using will-change to determine whether it provides a benefit.

For most websites, the best starting point is to leave will-change at auto and introduce specific hints only when necessary.

Browser Support

The CSS will-change property is widely supported in modern browsers, including Chrome, Edge, Firefox, Safari, and Opera.

Although the property is broadly available, browsers may implement different rendering optimizations in response to the same hint. Compatibility does not guarantee a performance improvement.

For detailed compatibility information, visit Can I Use? .

Specifications

The will-change property is defined in the CSS Will Change Module Level 1 specification.