Animations
๐ Covered in this chapter:
@keyframes ยท animation-name ยท duration ยท timing ยท delay ยท iteration-count ยท direction ยท fill-mode ยท play-state ยท Loading ยท Entrance ยท Exit ยท Reduced Motion
Welcome to Chapter 35: Animations โ part of the CSS Complete Roadmap. This lesson covers all subtopics with clear explanations, code examples, and best practices used in professional web development.
1@keyframes & Animation Properties
CSS โ Fade Inโถ Try in Editor
@keyframes fade-in {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.card {
animation: fade-in 400ms ease-out;
}
animation-iteration-count: infiniteโ loading spinnersanimation-direction: alternateโ back and forthanimation-fill-mode: forwardsโ end state retainanimation-play-state: pausedโ pause on hover
2Loading, Entrance & Exit Animations
CSS
@keyframes spin {
to { transform: rotate(360deg); }
}
.spinner {
animation: spin 800ms linear infinite;
}
@keyframes slide-out {
to { opacity: 0; transform: translateX(-100%); }
}
.toast-exit {
animation: slide-out 300ms ease-in forwards;
}
Reduced motion: Always respect prefers-reduced-motion: reduce โ disable or simplify animations for vestibular disorder users.