Lesson 22 of 50
cssKeyframe Animations
12 mins
Course progress44%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 22 of 50
css12 mins
Keep these ideas in mind as you work through the lesson.
Keyframe animations describe a timeline of style changes. They differ from transitions because you can define multiple intermediate steps and repeat the animation indefinitely.
@keyframes <name> {
from { … } /* same as 0% */
25% { … } /* quarter‑way */
50% { … } /* half‑way */
to { … } /* same as 100% */
}
.selector {
animation: <name> <duration> <timing-function> <delay> <iteration-count> <direction> <fill-mode>;
}
animation-name – Reference to the @keyframes block.animation-duration – Length of one cycle.animation-timing-function – Acceleration curve.animation-delay – Wait before the first cycle.animation-iteration-count – Number of repeats (infinite).animation-direction – normal, reverse, alternate, alternate-reverse.animation-fill-mode – none, forwards, backwards, both (controls style before/after the animation).@keyframes pulse {
0% { opacity:0.3; }
50% { opacity:1; }
100% { opacity:0.3; }
}
.loader {
width:40px; height:40px; border-radius:50%;
background:#0066cc; animation:pulse 1.2s infinite;
}
The element fades in and out, mimicking a loading indicator.
transform and opacity whenever possible – they stay on the compositor layer and avoid layout/repaint.prefers-reduced-motion to disable non‑essential animations for users who request them./* initial hidden state */
.reveal { opacity:0; transform:translateY(20px); }
/* when the .visible class is added (via IntersectionObserver) */
.reveal.visible {
animation: slideIn 0.6s forwards ease-out;
}
@keyframes slideIn {
to { opacity:1; transform:translateY(0); }
}
Pairing CSS animations with a tiny JavaScript
IntersectionObservergives you a smooth, performant scroll‑reveal effect.