Transitions: from one state to another
.button {
transition: background 0.2s ease;
}
.button:hover { background: var(--brand); }
A transition needs a trigger - a hover, a class toggle - and smoothly interpolates a property between its before and after value. It's the right tool for the vast majority of UI micro-interactions.
Animations: self-contained sequences
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.badge { animation: pulse 2s infinite; }
@keyframes defines multiple steps and can run automatically, looped, without waiting for a state change - useful for a loading spinner or a subtle looping attention cue.
Respect reduced motion
@media (prefers-reduced-motion: reduce) {
* { animation-duration: 0.001ms !important; }
}
A meaningful share of users have this preference set for real accessibility reasons, and it costs almost nothing to honour it.
Transitions for state changes, animations for sequences
transition is the right tool for anything moving between two states - a hover, a focus, an open/closed toggle. @keyframes earns its extra complexity when you need a sequence with more than two points, or something that runs on its own without a state change triggering it, like a loading spinner.
.btn { transition: transform .2s ease, box-shadow .2s ease; }
.btn:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,.15); }
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin 1s linear infinite; }
Stick to transform and opacity for anything that runs often
Animating width, top, or margin forces the browser to recalculate layout on every frame; animating transform and opacity can run entirely on the compositor thread, skipping layout and paint. On lower-powered devices that difference is the gap between a smooth 60fps interaction and a visibly stuttering one - worth checking with dev tools' paint-flashing overlay on anything animated frequently.