|

CSS 53 ๐Ÿ’ป transitions

CSS transitions let you smoothly animate changes to CSS properties over a specified duration. They add polish, interactivity, and visual appeal โ€” turning abrupt state changes into fluid motion.


What is a Transition?

A transition defines how a CSS property changes from one state to another over time. Instead of instantly jumping from red to blue, the color gradually shifts over the specified duration.

Key Benefits

BenefitDescription
Smooth animationsGradual changes instead of instant jumps
InteractivityResponds to hover, focus, and active states
PerformanceHardware-accelerated for transform and opacity
SimplicityPure CSS โ€” no JavaScript required
CustomizableControl duration, timing, and delay

The Four Transition Properties

The transition shorthand combines four individual properties:

PropertyDescriptionDefault
transition-propertyWhich property to animateall
transition-durationHow long the transition takes0s
transition-timing-functionSpeed curve of the transitionease
transition-delayWait before starting0s

1. transition-property

Specifies which CSS property should transition.

.box {
    transition-property: background-color, transform;
}
ValueDescription
noneNo property transitions
allAll animatable properties transition
property-nameSpecific property (e.g., background-color)
MultipleComma-separated list

Best practice: Specify individual properties rather than all for better performance.


2. transition-duration

Specifies how long the transition takes.

.box {
    transition-duration: 0.5s;
}
ValueDescription
0sNo transition (instant)
0.5sHalf a second
1sOne second
500ms500 milliseconds (same as 0.5s)

Note: If duration is 0s, the transition is instant โ€” no animation occurs.


3. transition-timing-function

Specifies the speed curve of the transition.

.box {
    transition-timing-function: ease-in-out;
}
ValueDescription
easeSlow start, fast middle, slow end (default)
linearConstant speed
ease-inSlow start, fast end
ease-outFast start, slow end
ease-in-outSlow start, fast middle, slow end
cubic-bezier(n,n,n,n)Custom curve
steps(n)Stepped animation

4. transition-delay

Specifies how long to wait before starting the transition.

.box {
    transition-delay: 0.2s;
}
ValueDescription
0sStart immediately (default)
0.2sWait 200ms before starting
1sWait 1 second

The transition Shorthand

/* Syntax */
transition: <property> <duration> <timing-function> <delay>;

/* Examples */
transition: background-color 0.5s ease;           /* property, duration, timing */
transition: transform 0.3s ease-in-out 0.1s;      /* all four values */
transition: background-color 0.5s, transform 0.3s; /* multiple properties */
transition: all 0.3s ease;                         /* all properties */

Complete Example

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CSS Transitions</title>
    <style>
        *, *::before, *::after {
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            padding: 20px;
            background: #f8f9fa;
            color: #333;
            max-width: 1200px;
            margin: 0 auto;
            line-height: 1.6;
        }

        h1 {
            color: #007bff;
            border-bottom: 3px solid #007bff;
            padding-bottom: 10px;
        }

        h2 {
            color: #28a745;
            border-left: 4px solid #28a745;
            padding-left: 15px;
            margin-top: 30px;
        }

        h3 {
            color: #333;
            margin-top: 20px;
        }

        section {
            background: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            margin: 20px 0;
        }

        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            padding: 15px;
            border-radius: 8px;
            overflow-x: auto;
            font-family: 'Courier New', monospace;
            font-size: 0.9rem;
            line-height: 1.8;
            margin: 10px 0;
        }

        .reference-table {
            width: 100%;
            border-collapse: collapse;
            margin: 15px 0;
        }

        .reference-table th,
        .reference-table td {
            padding: 10px;
            border: 1px solid #ddd;
            text-align: left;
        }

        .reference-table th {
            background: #007bff;
            color: white;
        }

        .reference-table tr:nth-child(even) {
            background: #f8f9fa;
        }

        .note {
            font-size: 0.9rem;
            color: #6c757d;
            margin-top: 5px;
        }

        .highlight {
            background: #ffc107;
            color: #333;
            padding: 2px 6px;
            border-radius: 4px;
            font-weight: bold;
        }

        /* ====== DEMO AREA ====== */
        .demo-area {
            display: flex;
            flex-wrap: wrap;
            gap: 30px;
            justify-content: center;
            align-items: center;
            padding: 40px 20px;
            background: #e9ecef;
            border-radius: 8px;
            margin: 15px 0;
            min-height: 200px;
        }

        .box {
            width: 120px;
            height: 120px;
            background: #007bff;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 0.85rem;
            border-radius: 12px;
            cursor: pointer;
            text-align: center;
            padding: 10px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
        }

        /* ====== BASIC TRANSITION ====== */
        .transition-box {
            width: 150px;
            height: 150px;
            background-color: #dc3545;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            border-radius: 12px;
            transition: background-color 0.5s ease, transform 0.3s ease;
            cursor: pointer;
            text-align: center;
            padding: 10px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
        }

        .transition-box:hover {
            background-color: #007bff;
            transform: scale(1.2);
        }

        /* ====== TIMING FUNCTIONS ====== */
        .timing-ease {
            transition: transform 1s ease;
        }
        .timing-ease:hover {
            transform: translateX(100px);
        }

        .timing-linear {
            transition: transform 1s linear;
        }
        .timing-linear:hover {
            transform: translateX(100px);
        }

        .timing-ease-in {
            transition: transform 1s ease-in;
        }
        .timing-ease-in:hover {
            transform: translateX(100px);
        }

        .timing-ease-out {
            transition: transform 1s ease-out;
        }
        .timing-ease-out:hover {
            transform: translateX(100px);
        }

        .timing-ease-in-out {
            transition: transform 1s ease-in-out;
        }
        .timing-ease-in-out:hover {
            transform: translateX(100px);
        }

        .timing-custom {
            transition: transform 1s cubic-bezier(0, 1, 1, 0);
        }
        .timing-custom:hover {
            transform: translateX(100px);
        }

        /* ====== DURATION COMPARISON ====== */
        .duration-fast {
            transition: transform 0.2s ease;
        }
        .duration-fast:hover {
            transform: scale(1.3);
        }

        .duration-medium {
            transition: transform 0.5s ease;
        }
        .duration-medium:hover {
            transform: scale(1.3);
        }

        .duration-slow {
            transition: transform 1.5s ease;
        }
        .duration-slow:hover {
            transform: scale(1.3);
        }

        /* ====== DELAY COMPARISON ====== */
        .delay-none {
            transition: transform 0.5s ease 0s;
        }
        .delay-none:hover {
            transform: translateY(-30px);
        }

        .delay-short {
            transition: transform 0.5s ease 0.2s;
        }
        .delay-short:hover {
            transform: translateY(-30px);
        }

        .delay-long {
            transition: transform 0.5s ease 0.5s;
        }
        .delay-long:hover {
            transform: translateY(-30px);
        }

        /* ====== MULTIPLE PROPERTIES ====== */
        .multi-transition {
            transition: 
                background-color 0.5s ease,
                transform 0.3s ease,
                border-radius 0.4s ease,
                box-shadow 0.5s ease;
        }

        .multi-transition:hover {
            background-color: #28a745;
            transform: rotate(10deg) scale(1.1);
            border-radius: 50%;
            box-shadow: 0 10px 30px rgba(40, 167, 69, 0.4);
        }

        /* ====== PRACTICAL: BUTTON ====== */
        .btn-transition {
            padding: 15px 35px;
            background: #007bff;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 1em;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s ease;
            margin: 5px;
        }

        .btn-transition:hover {
            background: #28a745;
            transform: translateY(-3px);
            box-shadow: 0 8px 20px rgba(40, 167, 69, 0.3);
        }

        .btn-transition:active {
            transform: translateY(-1px);
            box-shadow: 0 4px 10px rgba(40, 167, 69, 0.2);
        }

        /* ====== PRACTICAL: CARD ====== */
        .card-transition {
            background: white;
            border: 2px solid #ddd;
            border-radius: 12px;
            padding: 25px;
            max-width: 300px;
            margin: 15px auto;
            transition: all 0.3s ease;
            cursor: pointer;
            text-align: center;
        }

        .card-transition:hover {
            transform: translateY(-8px);
            border-color: #007bff;
            box-shadow: 0 15px 35px rgba(0, 123, 255, 0.15);
        }

        .card-transition h4 {
            margin-top: 0;
            color: #007bff;
            transition: color 0.3s ease;
        }

        .card-transition:hover h4 {
            color: #28a745;
        }

        /* ====== PRACTICAL: TOGGLE SWITCH ====== */
        .toggle-switch {
            position: relative;
            width: 70px;
            height: 36px;
            background: #ccc;
            border-radius: 18px;
            cursor: pointer;
            transition: background 0.3s ease;
            margin: 20px auto;
        }

        .toggle-switch::after {
            content: "";
            position: absolute;
            top: 3px;
            left: 3px;
            width: 30px;
            height: 30px;
            background: white;
            border-radius: 50%;
            transition: transform 0.3s ease, background 0.3s ease;
            box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        }

        .toggle-switch:hover {
            background: #28a745;
        }

        .toggle-switch:hover::after {
            transform: translateX(34px);
            background: #fff;
        }

        /* ====== PRACTICAL: FADE-IN ====== */
        .fade-container {
            display: flex;
            gap: 20px;
            justify-content: center;
            flex-wrap: wrap;
            margin: 15px 0;
        }

        .fade-box {
            width: 100px;
            height: 100px;
            background: linear-gradient(135deg, #007bff, #6c5ce7);
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 0.8rem;
            opacity: 0.3;
            transition: opacity 0.5s ease, transform 0.5s ease;
            cursor: pointer;
        }

        .fade-box:hover {
            opacity: 1;
            transform: translateY(-10px);
        }

        /* ====== TIPS ====== */
        .tip-box {
            padding: 15px;
            border-radius: 8px;
            margin: 10px 0;
            border-left: 4px solid #007bff;
            background: #f8f9fa;
        }

        .tip-box.success { border-left-color: #28a745; }
        .tip-box.warning { border-left-color: #ffc107; }
        .tip-box.danger { border-left-color: #dc3545; }
    </style>
</head>
<body>

    <h1>CSS Transitions</h1>

    <!-- ====== 1. BASIC TRANSITION ====== -->
    <section>
        <h2>1. Basic Transition</h2>
        <p>Hover over the box to see the smooth transition.</p>

        <div class="demo-area">
            <div class="transition-box">Hover Over Me!</div>
        </div>

        <div class="code-block">
            .transition-box {
                transition: background-color 0.5s ease, transform 0.3s ease;
            }

            .transition-box:hover {
                background-color: #007bff;
                transform: scale(1.2);
            }
        </div>
    </section>

    <!-- ====== 2. TIMING FUNCTIONS ====== -->
    <section>
        <h2>2. Timing Functions</h2>
        <p>Each box uses a different timing function. Hover to compare the motion.</p>

        <div class="demo-area" style="flex-direction: column; gap: 15px;">
            <div class="box timing-ease" style="width: 200px; height: 60px;">ease (default)</div>
            <div class="box timing-linear" style="width: 200px; height: 60px; background: #28a745;">linear</div>
            <div class="box timing-ease-in" style="width: 200px; height: 60px; background: #dc3545;">ease-in</div>
            <div class="box timing-ease-out" style="width: 200px; height: 60px; background: #ffc107; color: #333;">ease-out</div>
            <div class="box timing-ease-in-out" style="width: 200px; height: 60px; background: #6c5ce7;">ease-in-out</div>
            <div class="box timing-custom" style="width: 200px; height: 60px; background: #17a2b8;">cubic-bezier(0,1,1,0)</div>
        </div>

        <div class="code-block">
            .timing-ease        { transition: transform 1s ease; }
            .timing-linear      { transition: transform 1s linear; }
            .timing-ease-in     { transition: transform 1s ease-in; }
            .timing-ease-out    { transition: transform 1s ease-out; }
            .timing-ease-in-out { transition: transform 1s ease-in-out; }
            .timing-custom      { transition: transform 1s cubic-bezier(0, 1, 1, 0); }
        </div>
    </section>

    <!-- ====== 3. DURATION COMPARISON ====== -->
    <section>
        <h2>3. Duration Comparison</h2>
        <p>Each box uses a different duration. Hover to compare the speed.</p>

        <div class="demo-area">
            <div class="box duration-fast" style="background: #28a745;">0.2s</div>
            <div class="box duration-medium" style="background: #ffc107; color: #333;">0.5s</div>
            <div class="box duration-slow" style="background: #dc3545;">1.5s</div>
        </div>

        <div class="code-block">
            .duration-fast   { transition: transform 0.2s ease; }
            .duration-medium { transition: transform 0.5s ease; }
            .duration-slow   { transition: transform 1.5s ease; }
        </div>
    </section>

    <!-- ====== 4. DELAY COMPARISON ====== -->
    <section>
        <h2>4. Delay Comparison</h2>
        <p>Each box has a different delay before the transition starts.</p>

        <div class="demo-area">
            <div class="box delay-none" style="background: #007bff;">0s delay</div>
            <div class="box delay-short" style="background: #28a745;">0.2s delay</div>
            <div class="box delay-long" style="background: #dc3545;">0.5s delay</div>
        </div>

        <div class="code-block">
            .delay-none  { transition: transform 0.5s ease 0s; }
            .delay-short { transition: transform 0.5s ease 0.2s; }
            .delay-long  { transition: transform 0.5s ease 0.5s; }
        </div>
    </section>

    <!-- ====== 5. MULTIPLE PROPERTIES ====== -->
    <section>
        <h2>5. Multiple Properties</h2>
        <p>This box transitions multiple properties at once โ€” background, transform, border-radius, and shadow.</p>

        <div class="demo-area">
            <div class="box multi-transition">Hover Me</div>
        </div>

        <div class="code-block">
            .multi-transition {
                transition: 
                    background-color 0.5s ease,
                    transform 0.3s ease,
                    border-radius 0.4s ease,
                    box-shadow 0.5s ease;
            }

            .multi-transition:hover {
                background-color: #28a745;
                transform: rotate(10deg) scale(1.1);
                border-radius: 50%;
                box-shadow: 0 10px 30px rgba(40, 167, 69, 0.4);
            }
        </div>
    </section>

    <!-- ====== 6. PRACTICAL: BUTTON ====== -->
    <section>
        <h2>6. Practical Example: Button</h2>
        <p>Hover and click the buttons to see the transition effects.</p>

        <div style="text-align: center; margin: 15px 0;">
            <button class="btn-transition">Hover Me</button>
            <button class="btn-transition">Click Me</button>
            <button class="btn-transition">Press Me</button>
        </div>

        <div class="code-block">
            .btn-transition {
                transition: all 0.3s ease;
            }

            .btn-transition:hover {
                background: #28a745;
                transform: translateY(-3px);
                box-shadow: 0 8px 20px rgba(40, 167, 69, 0.3);
            }

            .btn-transition:active {
                transform: translateY(-1px);
                box-shadow: 0 4px 10px rgba(40, 167, 69, 0.2);
            }
        </div>
    </section>

    <!-- ====== 7. PRACTICAL: CARD ====== -->
    <section>
        <h2>7. Practical Example: Card</h2>
        <p>Hover over the card to see the lift and shadow transition.</p>

        <div class="card-transition">
            <h4>Interactive Card</h4>
            <p>Hover over this card to see the transition effect. The border color, shadow, and position all transition smoothly.</p>
        </div>

        <div class="code-block">
            .card-transition {
                transition: all 0.3s ease;
            }

            .card-transition:hover {
                transform: translateY(-8px);
                border-color: #007bff;
                box-shadow: 0 15px 35px rgba(0, 123, 255, 0.15);
            }

            .card-transition h4 {
                transition: color 0.3s ease;
            }

            .card-transition:hover h4 {
                color: #28a745;
            }
        </div>
    </section>

    <!-- ====== 8. PRACTICAL: TOGGLE SWITCH ====== -->
    <section>
        <h2>8. Practical Example: Toggle Switch</h2>
        <p>Hover over the switch to see the transition effect.</p>

        <div style="text-align: center;">
            <div class="toggle-switch"></div>
        </div>

        <div class="code-block">
            .toggle-switch {
                transition: background 0.3s ease;
            }

            .toggle-switch::after {
                transition: transform 0.3s ease, background 0.3s ease;
            }

            .toggle-switch:hover {
                background: #28a745;
            }

            .toggle-switch:hover::after {
                transform: translateX(34px);
            }
        </div>
    </section>

    <!-- ====== 9. PRACTICAL: FADE-IN ====== -->
    <section>
        <h2>9. Practical Example: Fade-In</h2>
        <p>Hover over each box to see it fade in and lift up.</p>

        <div class="fade-container">
            <div class="fade-box">Fade 1</div>
            <div class="fade-box">Fade 2</div>
            <div class="fade-box">Fade 3</div>
            <div class="fade-box">Fade 4</div>
        </div>

        <div class="code-block">
            .fade-box {
                opacity: 0.3;
                transition: opacity 0.5s ease, transform 0.5s ease;
            }

            .fade-box:hover {
                opacity: 1;
                transform: translateY(-10px);
            }
        </div>
    </section>

    <!-- ====== 10. REFERENCE TABLES ====== -->
    <section>
        <h2>10. Reference Tables</h2>

        <h3>Transition Properties</h3>
        <table class="reference-table">
            <tr>
                <th>Property</th>
                <th>Description</th>
                <th>Default</th>
            </tr>
            <tr>
                <td><code>transition-property</code></td>
                <td>Which property to animate</td>
                <td><code>all</code></td>
            </tr>
            <tr>
                <td><code>transition-duration</code></td>
                <td>How long the transition takes</td>
                <td><code>0s</code></td>
            </tr>
            <tr>
                <td><code>transition-timing-function</code></td>
                <td>Speed curve</td>
                <td><code>ease</code></td>
            </tr>
            <tr>
                <td><code>transition-delay</code></td>
                <td>Wait before starting</td>
                <td><code>0s</code></td>
            </tr>
        </table>

        <h3>Timing Functions</h3>
        <table class="reference-table">
            <tr>
                <th>Value</th>
                <th>Description</th>
            </tr>
            <tr>
                <td><code>ease</code></td>
                <td>Slow start, fast middle, slow end (default)</td>
            </tr>
            <tr>
                <td><code>linear</code></td>
                <td>Constant speed</td>
            </tr>
            <tr>
                <td><code>ease-in</code></td>
                <td>Slow start, fast end</td>
            </tr>
            <tr>
                <td><code>ease-out</code></td>
                <td>Fast start, slow end</td>
            </tr>
            <tr>
                <td><code>ease-in-out</code></td>
                <td>Slow start, fast middle, slow end</td>
            </tr>
            <tr>
                <td><code>cubic-bezier(n,n,n,n)</code></td>
                <td>Custom speed curve</td>
            </tr>
            <tr>
                <td><code>steps(n)</code></td>
                <td>Stepped animation</td>
            </tr>
        </table>

        <h3>Common Transition Examples</h3>
        <table class="reference-table">
            <tr>
                <th>Example</th>
                <th>Description</th>
            </tr>
            <tr>
                <td><code>transition: all 0.3s ease;</code></td>
                <td>All properties, 0.3s, ease</td>
            </tr>
            <tr>
                <td><code>transition: background-color 0.5s;</code></td>
                <td>Background only, 0.5s</td>
            </tr>
            <tr>
                <td><code>transition: transform 0.3s ease-in-out 0.1s;</code></td>
                <td>Transform, 0.3s, custom timing, 0.1s delay</td>
            </tr>
            <tr>
                <td><code>transition: background-color 0.5s, transform 0.3s;</code></td>
                <td>Multiple properties with different durations</td>
            </tr>
        </table>

        <h3>Animatable Properties (Common)</h3>
        <table class="reference-table">
            <tr>
                <th>Property</th>
                <th>Notes</th>
            </tr>
            <tr>
                <td><code>opacity</code></td>
                <td>Hardware-accelerated, very smooth</td>
            </tr>
            <tr>
                <td><code>transform</code></td>
                <td>Hardware-accelerated, very smooth</td>
            </tr>
            <tr>
                <td><code>background-color</code></td>
                <td>Commonly used, works well</td>
            </tr>
            <tr>
                <td><code>color</code></td>
                <td>Works well for text</td>
            </tr>
            <tr>
                <td><code>box-shadow</code></td>
                <td>Can be expensive on large elements</td>
            </tr>
            <tr>
                <td><code>border-radius</code></td>
                <td>Works well</td>
            </tr>
            <tr>
                <td><code>width</code>/<code>height</code></td>
                <td>Can cause layout recalculation</td>
            </tr>
        </table>
    </section>

    <!-- ====== 11. BEST PRACTICES ====== -->
    <section>
        <h2>11. Best Practices</h2>

        <div style="background: #d4edda; padding: 20px; border-radius: 8px; border-left: 4px solid #28a745;">
            <h3 style="margin-top: 0; color: #155724;">โœ… Do This:</h3>
            <ul>
                <li>Use <code>transform</code> and <code>opacity</code> for the smoothest animations (hardware-accelerated)</li>
                <li>Specify individual properties instead of <code>all</code> for better performance</li>
                <li>Use short durations (0.2sโ€“0.5s) for UI feedback</li>
                <li>Use <code>ease</code> or <code>ease-in-out</code> for natural motion</li>
                <li>Add transitions to hover, focus, and active states</li>
                <li>Use <code>transition-delay</code> for staggered animations</li>
                <li>Respect <code>prefers-reduced-motion</code> for accessibility</li>
            </ul>
        </div>

        <div style="background: #f8d7da; padding: 20px; border-radius: 8px; border-left: 4px solid #dc3545; margin-top: 15px;">
            <h3 style="margin-top: 0; color: #721c24;">โŒ Don't Do This:</h3>
            <ul>
                <li>Don't animate <code>width</code>, <code>height</code>, <code>top</code>, or <code>left</code> (causes layout recalculation)</li>
                <li>Don't use long durations (> 1s) for UI feedback</li>
                <li>Don't forget to add <code>transition</code> to the base state (not just hover)</li>
                <li>Don't animate too many properties at once</li>
                <li>Don't use <code>transition: all</code> for everything</li>
                <li>Don't forget about <code>prefers-reduced-motion</code></li>
            </ul>
        </div>

        <div class="code-block">
            /* Accessibility: respect reduced motion */
            @media (prefers-reduced-motion: reduce) {
                .transition-box,
                .btn-transition,
                .card-transition {
                    transition: none;
                }
            }

            /* Better performance: use transform instead of top/left */
            .box {
                transition: transform 0.3s ease;
            }
            .box:hover {
                transform: translateY(-5px); /* Better than top: -5px */
            }
        </div>
    </section>

</body>
</html>

Quick Reference

PropertyDescriptionDefault
transition-propertyWhich property to animateall
transition-durationHow long the transition takes0s
transition-timing-functionSpeed curveease
transition-delayWait before starting0s

Timing Functions

ValueDescription
easeSlow start, fast middle, slow end (default)
linearConstant speed
ease-inSlow start, fast end
ease-outFast start, slow end
ease-in-outSlow start, fast middle, slow end
cubic-bezier(n,n,n,n)Custom speed curve

Common Transition Examples

ExampleDescription
transition: all 0.3s ease;All properties, 0.3s, ease
transition: background-color 0.5s;Background only, 0.5s
transition: transform 0.3s ease-in-out 0.1s;Transform, 0.3s, custom timing, 0.1s delay
transition: background-color 0.5s, transform 0.3s;Multiple properties

Best Practices

โœ… Do This:

/* Smooth hover effect */
.box {
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.box:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

/* Button feedback */
.btn {
    transition: all 0.2s ease;
}
.btn:hover {
    background: #0056b3;
}
.btn:active {
    transform: scale(0.98);
}

/* Staggered animation */
.item:nth-child(1) { transition-delay: 0s; }
.item:nth-child(2) { transition-delay: 0.1s; }
.item:nth-child(3) { transition-delay: 0.2s; }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .box {
        transition: none;
    }
}

โŒ Don’t Do This:

/* Don't animate layout properties */
.box {
    transition: width 0.3s, height 0.3s; /* Causes layout recalculation */
}

/* Don't forget the base transition */
.box:hover {
    transition: all 0.3s; /* Too late โ€” transition won't work on mouse-out */
}

/* Don't use excessively long durations */
.box {
    transition: all 3s; /* Too slow for UI */
}

/* Don't use transition: all for everything */
.box {
    transition: all 0.5s; /* Can cause unexpected animations */
}

Pro Tip: Transitions are the key to polished, interactive interfaces. Use transform and opacity for the smoothest animations (they’re hardware-accelerated). Keep durations short โ€” 0.2sโ€“0.5s for UI feedback. Always apply the transition to the base state, not just the hover state, so it works on both mouse-in and mouse-out. Use prefers-reduced-motion to respect users who are sensitive to animation. And remember: less is more โ€” a few well-placed transitions are better than animating everything!


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!