Like transition-duration, animation-duration defaults to 0s, meaning an animation referencing a valid @keyframes name still technically runs, but completes so instantaneously that no visible animation is perceptible at all unless an explicit, nonzero duration is set. For a looping animation set with animation-iteration-count: infinite, animation-duration specifically controls the length of just one single cycle through the keyframes, with that same duration then repeating indefinitely for every subsequent loop.
1Understanding Animation-duration
Like transition-duration, animation-duration defaults to 0s, meaning an animation referencing a valid @keyframes name still technically runs, but completes so instantaneously that no visible animation is perceptible at all unless an explicit, nonzero duration is set. For a looping animation set with animation-iteration-count: infinite, animation-duration specifically controls the length of just one single cycle through the keyframes, with that same duration then repeating indefinitely for every subsequent loop.
Just like transition-duration, animation-duration defaults to 0s — an animation referencing a correctly-defined @keyframes rule still produces no visible motion at all if this duration is left unset.
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
.badge {
animation: pulse 2s infinite;
}2Practical Example
Here is a real-world application of Animation-duration showing how it is used in production CSS code.
.spinner {
animation-name: spin;
/* animation-duration omitted, defaults to 0s */
}3Best Practices
Follow these guidelines when working with Animation-duration:
1. Always specify an explicit, nonzero animation-duration, since it defaults to 0s and produces no visible animation otherwise, even with valid keyframes defined
2. For a looping animation, remember animation-duration sets the length of just one single cycle, which then repeats that same duration for every subsequent loop
3. Choose an animation-duration that matches the perceived complexity or distance of the motion, a longer, more elaborate multi-stage animation generally needs more time than a simple, subtle two-stage one
Tip: Just like transition-duration, animation-duration defaults to 0s — an animation referencing a correctly-defined @keyframes rule still produces no visible motion at all if this duration is left unset.
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
.badge {
animation: pulse 2s infinite;
}