animation-fill-mode
Example
.notice {
animation: fade-out 0.5s;
}
@keyframes fade-out {
to { opacity: 0; }
}.notice {
animation: fade-out 0.5s forwards;
}
@keyframes fade-out {
to { opacity: 0; }
}With 'forwards', the element keeps the last keyframe instead of popping back to full opacity.
Common mistakes
- The element jumps back to its original style when the animation ends.
- Hover styles stop working because a 'forwards' animation still overrides the property.
Key points
- Entry animations with a delay use 'backwards' or 'both', so the first keyframe applies during the delay.
- 'forwards' isn't used for state that other styles must change later, since the filled value overrides them.
Interview questions
What is the difference between forwards, backwards and both?
'forwards' keeps the last keyframe after the end, 'backwards' applies the first keyframe during the delay, and 'both' does both.
Why can't I change a property after a forwards animation?
The filled animation value still overrides normal styles. Remove the animation, or set the final value in the base styles instead.