Tailwind CSS - Will Change


Tailwind CSS Will Change is a collection of predefined classes that inform the browser about which element properties will change, helping to improve performance for animations and transitions.

Tailwind CSS Will Change Classes

Below is a list of Tailwind CSS Will Change classes that help improve performance by showing the browser which properties will change.

Class CSS Properties
will-change-auto will-change-auto;
will-change-scroll will-change: scroll-position;
will-change-contents will-change: contents;
will-change-transform will-change: transform;

Functionality of Tailwind CSS Will Change Classes

  • will-change-auto: This class allows the browser to decide how to manage changes.
  • will-change-scroll: This class helps improve performance for elements that will scroll.
  • will-change-contents: This class improves performance for elements with changing content.
  • will-change-transform: This class improves performance for elements with changing transforms.

Tailwind CSS Will Change Class Examples

Below are examples of Tailwind CSS Will Change classes that show how to help the browser manage different property changes for better performance.

Tailwind CSS Will-Change Auto and Scroll Classes

This example shows how to use Tailwind CSS's will-change classes. The will-change-auto class indicates that any CSS property of the element might change, while will-change-scroll specifically optimizes performance for scroll-related changes.

Example

  
<!DOCTYPE html>
<html lang="en">
<head>  
    <script src="https://cdn.tailwindcss.com"></script>
</head>

<body class="p-4">
    <h1 class="text-2xl font-bold mb-6">
        Tailwind CSS Will Change
    </h1>
    <h3 class="underline font-bold mb-2">
        will-change-auto
    </h3>
    <div class="will-change-auto bg-pink-200 p-2">
        <p>This box hints that any property 
            may change.
        </p>
    </div>
     <h3 class="underline font-bold mb-2 mt-6">
        will-change-scroll
    </h3>
    <div class="will-change-scroll p-4 bg-blue-200 
                max-h-24 overflow-y-auto">
            Scrollable content<br>inside this box....
        <br>Each step forward,<br>no matter
        <br>how small,<br>brings us closer
        <br>to<br>our full 
        potential.
    </div>
</body>

</html>

Tailwind CSS Will-Change Content Example

This example shows Tailwind CSS's Will Change classes. The will-change-content class indicates that the content within the box might change. When the button is clicked, the text content of the box updates to a new message.

Example

<!DOCTYPE html>
<html lang="en">
<head>  
    <script src="https://cdn.tailwindcss.com"></script>
</head>

<body class="p-4">
   <h1 class="text-2xl font-bold">
       Tailwind CSS Will Change Classes
   </h1>
   <div class="p-6 max-w-lg">
        <div class="will-change-content bg-purple-200 p-4 
                    border border-purple-500 rounded">
            <p id="content-box">
                This box hints that content might change.
            </p>
        </div>
        <!-- Button to Change Content -->
        <button onclick="document.getElementById
            ('content-box').textContent = 
                        'Content has been updated!';" 
            class="bg-blue-600 text-white p-2 mt-4">
                Change Content
        </button>
    </div>
</body>

</html> 

Tailwind CSS Will-Change Classes with Hover Effects

This example shows Tailwind CSS's Will Change classes: 'will-change-auto' indicates that any property might change; 'will-change-transform' smooths transformations like scaling on hover; 'will-change-contents' adjusts opacity when content changes on hover; and 'will-change-scroll' improves performance for scrolling areas.

Example

<!DOCTYPE html>
<html lang="en">
<head>  
    <script src="https://cdn.tailwindcss.com"></script>
</head> 

<body class="p-4">
    <h1 class="text-2xl font-bold mb-6">
        Tailwind CSS Will Change Classes
    </h1>
    <div class="grid grid-cols-2 gap-4"> 
        <div>
            <h3 class="underline font-bold mb-2">
                Will Change Auto
            </h3>
            <div class="will-change-auto bg-gray-200 p-2">
                This box hints that any property might 
                change.
            </div>
        </div>
 
        <div>
            <h3 class="underline font-bold mb-2">
                Will Change Transform
            </h3>
            <div class="will-change-transform bg-green-200 p-2 
                        hover:scale-110">
                Hover to see the transform scale effect.
            </div>
        </div>
 
        <div>
            <h3 class="underline font-bold mb-2">
                Will Change Contents
            </h3>
            <div class="will-change-contents bg-yellow-200 p-4 
                        hover:opacity-50">
                Hover to see the opacity change effect.
            </div>
        </div> 
 
        <div>
            <h3 class="underline font-bold mb-2">
                Will Change Scroll
            </h3>
            <div class="will-change-scroll bg-blue-200 p-2 
                        max-h-24 overflow-y-auto">
                Scroll inside to see the scroll effect...
                <br>Learning<br>is a<br>lifelong journey
                <br>that 
                <br>opens doors to new<br>opportunities
                <br>and<br>personal growth.
            </div>
        </div> 
    </div>
</body>

</html>