Kombai Logo

Tailwind CSS Will Change

The will-change property in CSS serves as a hint to browsers, allowing them to pre-optimize certain elements on a webpage before they change. This proactive behavior can lead to better performance and reduced visual glitches during animations or transitions.

Tailwind CSS provides set of utilities, simplifying the implementation of the will-change property across your projects. In this document, we’ll explore its usage, conditional application, customization, and advanced implementations within Tailwind.

ClassPropertiesExample
will-change-autowill-change: auto;<div className="will-change-auto"></div>
will-change-scrollwill-change: scroll-position;<div className="will-change-scroll"></div>
will-change-contentswill-change: contents;<div className="will-change-contents"></div>
will-change-transformwill-change: transform;<div className="will-change-transform"></div>

Overview of Will Change

Adding the Will Change

Tailwind provides four predefined will-change utilities- will-change-auto, will-change-scroll, will-change-contents, and will-change-transform. Use these utilities to help the browser anticipate upcoming changes to an element, improving animation performance.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Only apply these classes immediately before the element updates, and revert to will-change-auto once the update is finished. Remember that will-change is meant to address specific performance concerns, so don’t overuse it or apply it preemptively—doing so can actually harm your page’s performance.

States and Responsiveness

Hover and Focus States

Tailwind allows you to conditionally apply the utility class on certain states like hover and focus. Use Tailwind's state modifiers like- hover, focus, etc. to apply the utility only when these states are active, e.g., hover:will-change-transform.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Breakpoint Modifiers

Tailwind CSS provides breakpoint modifiers to conditionally apply will-change only when the screen hits the defined breakpoint. This is especially helpful for applying effects only on specific screens. Use Tailwind's breakpoint modifiers like- sm, md, etc., to apply the utility only on these breakpoints and above.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Custom Will Change

Extending the Theme

Tailwind lets you customize the theme file to create new utilities beyond the default ones. Inside your tailwind.config.js, modify the willChange property under the theme.extend configuration.

In the below example, you have access to the custom utility- will-change-opacity:

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Using Arbitrary Values

Tailwind also lets you define arbitrary values directly in your classes for one-off use cases. Just use the square bracket syntax [value] wherever you need it, e.g., will-change-[opacity].

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Real World Examples

Animated Product Cards

This example demonstrates a grid of product cards with smooth hover animations using will-change for better performance.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Vertical Timeline Cards

This example shows a vertical timeline with smooth hover on cover images using will-change for better performance.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Interactive Team Member Cards

This example showcases team member cards with smooth hover effects using will-change for better performance.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Animated Feature Showcase

This example demonstrates an animated feature showcase with hover animations using will-change will-change for better performance.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Animated Pricing Table

This example shows a pricing table with hover animations using will-change for better performance.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Customization Examples

Smooth Card Transitions

This example demonstrates a card component with smooth transitions and custom will-change utility.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Floating Navigation Menu

This example shows a navigation menu with smooth position transitions and custom will-change utility.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Animated Profile Cards

This example shows profile cards with smooth opacity, position transitions, and custom will-change utility.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Best Practices

Use with Caution

Applying will-change should be a carefully considered decision within your design and animation strategy. It should not be used indiscriminately, as excessive application can lead to unintended performance issues rather than optimizations. Instead of applying will-change broadly, limit its usage to elements that genuinely require rendering optimizations.

Before integrating will-change, ensure that animations, transitions, and layout adjustments align with a well-defined motion design system. Elements should transition smoothly, avoiding abrupt changes that might create inconsistencies within the interface. Rather than treating will-change as a default solution, establish a structured approach to animations—prioritizing standard CSS optimizations first and resorting to will-change only when all other techniques have been exhausted.

Leverage Utility Combinations

When applying will-change-transform, it pairs well with transition-transform and duration-* classes to ensure optimized GPU rendering. Similarly, using will-change-[opacity] alongside opacity-* classes enables smooth fading effects.

For hover interactions, group-hover or hover: variants can be used in conjunction with will-change to ensure optimized responsiveness. For instance, when hovering over a card, you may want to trigger subtle scaling or shadow effects. In such cases, pairing will-change with hover:scale-* or hover:shadow-* ensures that animations remain fluid and efficient.

Accessibility Considerations

Enhance Readability and Navigability

If applied to critical elements, users may experience unexpected rendering issues, making content harder to read. Ensure that will-change is only used where necessary and does not interfere with essential content.

For users who rely on assistive technologies, such as screen readers, avoid applying will-change to structural elements that contribute to content flow. The improper use of will-change can cause delays in rendering, which may disrupt the user's ability to navigate a page efficiently. To mitigate this, apply will-change sparingly and primarily to elements that enhance interaction rather than those that contain primary content.

Focus on High Contrast

When using will-change with opacity or color transitions in Tailwind CSS, be mindful that it does not directly control transitions but instead hints to the browser about expected changes. This means will-change itself does not guarantee smooth opacity transitions or color shifts—it simply allows the browser to optimize rendering in advance.

For accessibility, ensure that opacity and color changes maintain a sufficient contrast ratio throughout the animation. Sudden shifts in transparency may temporarily reduce text or element visibility, which can be problematic for users with low vision.