The animation Shorthand
You'll learn how to combine all animation properties into one line for cleaner, more maintainable code.
What Is the animation Shorthand?
Instead of writing out animation-name, animation-duration, animation-timing-function, animation-delay, animation-iteration-count, animation-direction, animation-fill-mode, and animation-play-state as separate properties, CSS lets you combine them all into a single animation declaration. Think of it like packing a suitcase: rather than carrying eight separate bags, you pack everything into one organized piece of luggage.
How It Works
The animation shorthand follows this order (though only name and duration are required):
.element {
animation: name duration timing-function delay iteration-count direction fill-mode play-state;
}
Here's a practical example:
.box {
animation: slide 2s ease-in-out 0.5s infinite alternate both running;
}
This single line replaces eight separate property declarations! You can also omit values you don't need — CSS will use defaults:
.simple {
animation: fadeIn 1s;
/* Uses default values for the rest */
}
Order Matters (Mostly)
The two time values can be tricky: the first time is always duration, the second (if present) is delay. Other values can be in any order since CSS can tell them apart by type.
Key Takeaway: The animation shorthand condenses up to eight animation properties into one declaration, making your code cleaner and easier to maintain — just remember that duration comes before delay when using multiple time values.