animation-delay defaults to 0s, meaning an animation starts playing immediately once the element renders — a nonzero delay instead postpones the actual start of the animation's first cycle by that amount of time, which is a common technique for staggering several similar elements' animations so they don't all begin playing in perfect, simultaneous unison. Combined with animation-fill-mode: backwards, an element can also be made to display its animation's very first (0%) keyframe styles during the delay period itself, rather than showing its normal, un-animated CSS styles while waiting for the delayed animation to actually begin.
1Understanding Animation-delay
animation-delay defaults to 0s, meaning an animation starts playing immediately once the element renders — a nonzero delay instead postpones the actual start of the animation's first cycle by that amount of time, which is a common technique for staggering several similar elements' animations so they don't all begin playing in perfect, simultaneous unison. Combined with animation-fill-mode: backwards, an element can also be made to display its animation's very first (0%) keyframe styles during the delay period itself, rather than showing its normal, un-animated CSS styles while waiting for the delayed animation to actually begin.
Combine a nonzero animation-delay with animation-fill-mode: backwards specifically when an element should display its animation's starting (0%) keyframe styles throughout the delay period, rather than its normal, non-animated CSS styles, avoiding an unwanted visual flash or jump right as the delayed animation actually begins.
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.item-1 { animation: fadeInUp 0.5s ease forwards; animation-delay: 0s; }
.item-2 { animation: fadeInUp 0.5s ease forwards; animation-delay: 0.15s; }
.item-3 { animation: fadeInUp 0.5s ease forwards; animation-delay: 0.3s; }2Practical Example
Here is a real-world application of Animation-delay showing how it is used in production CSS code.
.badge {
animation: pulse 1s ease-in-out infinite;
animation-delay: -0.5s;
}3Best Practices
Follow these guidelines when working with Animation-delay:
1. Use staggered animation-delay values across a set of similar elements to create a sequential, cascading effect rather than everything animating in perfect unison
2. Combine a nonzero animation-delay with animation-fill-mode: backwards to avoid a visual jump between an element's normal pre-animation styles and its keyframe's actual starting styles
3. Remember animation-delay only postpones when an animation's first cycle begins — it doesn't affect animation-duration, the length of time each individual cycle itself actually takes
Tip: Combine a nonzero animation-delay with animation-fill-mode: backwards specifically when an element should display its animation's starting (0%) keyframe styles throughout the delay period, rather than its normal, non-animated CSS styles, avoiding an unwanted visual flash or jump right as the delayed animation actually begins.
@keyframes fadeInUp {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
.item-1 { animation: fadeInUp 0.5s ease forwards; animation-delay: 0s; }
.item-2 { animation: fadeInUp 0.5s ease forwards; animation-delay: 0.15s; }
.item-3 { animation: fadeInUp 0.5s ease forwards; animation-delay: 0.3s; }