Transitions react to a change: two values (before and after), one trigger, automatic reversing. Animations are declared: @keyframes names a sequence of states and animation runs it on any element it applies to, including on page load or insertion, with no change needed.
What animations add:
- Keyframes.
from/toor percentages, each with its ownanimation-timing-function. A missing0%or100%keyframe is built from the element's computed value, so@keyframes grow { to { scale: 1.2 } }starts from wherever the element is.!importantinside a keyframe is ignored. - Repetition.
animation-iteration-count(infinitefor loops) andanimation-direction(alternateswings back and forth). - Fill modes. The default
animation-fill-mode: nonemeans the animation affects nothing during its delay or after it ends: the element snaps back to its own value.backwardsapplies the first keyframe during the delay,forwardsholds the last one after the end,bothdoes both. - Composition.
animation-composition: add(Chrome 112, Firefox 115, Safari 16) adds keyframe values to the underlying value instead of replacing it, so two animations ontransformcan stack. - Events.
animationstart,animationiteration,animationend, andanimationcancelwhen it's removed early.
Lifecycle differences matter. Removing the class (or animation-name) cancels the animation and the value jumps back; there's no reverse like a transition's. Changing duration or other animation-* values updates the running animation without restarting it. display: none cancels it, and showing the element again starts it over.
In the cascade, animations sit above normal author declarations but below !important ones; transitions sit above !important.
Pick a transition for state changes (hover, open/closed) and a keyframe animation for anything that loops, plays on arrival, or needs more than two steps.