Transitioning Multiple Properties
You'll learn how to animate several CSS properties at once, each with its own timing and duration.
The Core Idea
So far you've learned to transition one property at a time, but real-world animations often need multiple properties changing simultaneously—yet with different speeds and delays. For example, you might want background color to fade quickly while width changes slowly. CSS lets you specify multiple properties in a single transition rule, giving each its own settings.
How It Works in Plain English
Think of a theater production where the lights dim in 2 seconds, the curtain opens in 5 seconds, and music fades in after a 1-second delay. Each element has its own timing, but they all happen "together" to create one cohesive effect. CSS transitions work the same way.
You can list multiple properties separated by commas, each with its own duration, timing function, and delay:
.button {
background-color: blue;
transform: scale(1);
opacity: 1;
transition: background-color 0.3s ease-in,
transform 0.5s ease-out 0.1s,
opacity 0.2s linear;
}
.button:hover {
background-color: green;
transform: scale(1.1);
opacity: 0.8;
}
Here, background color transitions in 0.3 seconds, transform takes 0.5 seconds with a 0.1s delay, and opacity changes in 0.2 seconds. Each property animates independently but all trigger on hover.
The Shortcut: all
If you want the same timing for everything, use transition: all 0.3s ease:
.card {
transition: all 0.3s ease;
}
This animates every property that changes. Use carefully—it can affect performance with many properties.
Key Takeaway: You can transition multiple properties with individual timing by listing them comma-separated, or use all to apply uniform transitions to every changing property.