Name
The @keyframes block gets a reusable animation name.
Keyframes describe a named animation over time. They are best for motion that runs without a direct one-step state change.
@keyframes pulse {
50% { opacity: 1; transform: scale(1.08); }
}
.dot { animation: pulse 1.8s ease-in-out infinite; }
Motion mental model
A transition animates from the old value to the new value when a state changes. A keyframe animation defines its own timeline.
Use keyframes for loading indicators, pulsing status lights, entrance sequences and repeating motion that needs more than a start and end state.
Good keyframe animations are purposeful and controlled. Infinite decorative motion can quickly become distracting or inaccessible.
The @keyframes block gets a reusable animation name.
Use from/to or percentages to describe frames.
animation-duration and timing-function control speed and feel.
iteration-count decides whether it runs once or loops.
Visual model
The animation begins with a known visual state.
Intermediate frames create rhythm.
Motion can pause, pulse or overshoot.
The animation lands or loops.
Good CSS versus fragile CSS
@keyframes pulse {
0%, 100% { opacity: .55; transform: scale(1); }
50% { opacity: 1; transform: scale(1.08); }
}
.status-dot { animation: pulse 1.8s ease-in-out infinite; }
@keyframes spin-jump {
100% { transform: rotate(360deg) translateY(-80px); }
}
* { animation: spin-jump .4s linear infinite; }
Rules of thumb
Choose keyframes when motion needs more than a simple state transition.
pulse-status is clearer than anim1.
Never attach animation to broad selectors like every element.
Loop only when the motion communicates active state or progress.
Decide whether the element keeps the first or last keyframe style.
Repeating animations should pause or simplify for reduced-motion users.
Production thinking
Keyframes let CSS communicate time, progress and activity, but they also carry the highest risk of decorative noise.
Infinite animation should be avoidable. Reduced-motion users should get a still or simplified state.
Document reusable animation names and do not scatter one-off keyframes across random component files.
Do not rely on animation to reveal essential information that is not otherwise present in HTML.
Live code lab
The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.
Mini assignment
Practice assignment
Try it yourself
Self-check
Answer these questions before moving on. If the motion has no purpose, no fallback or no state clarity, it is not production motion yet.
Senior audit upgrade
If a keyframe animation is important enough to ship, it is important enough to define what happens for users who prefer less motion.
Some decorative loops can simply stop.
A motion-heavy reveal can become an instant opacity or color change.
Some useful transitions can be made faster rather than removed completely.