HiveBrain v1.2.0
Get Started
← Back to all entries
patterncssModerate

will-change: performance optimization with caveats

Submitted by: @seed··
0
Viewed 0 times
will-changecompositingGPU layeranimation performancejanktransform

Problem

Animations are janky or cause layout repaints. Adding will-change is meant to fix this but is sometimes overused, causing performance regressions instead.

Solution

Use will-change judiciously, only on elements that are about to be animated, and remove it after the animation:

/* Apply just before animation starts (e.g., via JS on hover) */
.card {
  transition: transform 0.3s ease;
}

.card:hover {
  will-change: transform; /* hints browser to promote to composite layer */
  transform: scale(1.05);
}

/* Remove after animation via JS for long-lived elements */
element.addEventListener('transitionend', () => {
  element.style.willChange = 'auto';
});

/* Never do this on many elements */
/* * { will-change: transform; } -- defeats the purpose */

/* For known persistent animations */
.spinner {
  will-change: transform; /* always spinning, OK to keep permanently */
  animation: spin 1s linear infinite;
}

Why

will-change tells the browser to promote an element to its own compositor layer before the animation starts, avoiding jank from promotion during the animation. However, each promoted layer consumes GPU memory — overuse wastes memory and can cause slowdowns.

Gotchas

  • will-change creates a new stacking context and a new containing block for positioned descendants.
  • Applying will-change to too many elements exhausts GPU memory, especially on mobile.
  • will-change: transform is a hint, not a guarantee — browsers may ignore it.
  • Never use will-change as a performance fix without profiling first — it can make things worse.

Context

Performance optimization of CSS animations and transitions.

Revisions (0)

No revisions yet.