CSS Transition vs CSS Animation
A transition runs once, from one state to another, like on hover. An animation runs by itself through many steps and can loop.
CSS Transition
A CSS rule that makes a style change smooth. It runs between two states, like on hover.
A CSS transition makes a style change happen smoothly instead of all at once. You say which property to animate, how long it takes and which easing to use. When the value changes, like on hover, the browser fills in the steps. It only runs from one state to another, so it cannot loop. For more than two states, use a CSS animation.
CSS Animation
Keyframes written in CSS that the browser plays. It can loop and pass through many steps.
A CSS animation plays a set of keyframes written in CSS. You name the animation with an @keyframes rule and list how things look at points from 0% to 100%. Then you attach it to an element with a duration, an easing and how many times to repeat. Unlike a transition, it can run on its own, loop and pass through many states. It suits spinners, pulses and attention cues.
In one line
- CSS Transition
- A CSS rule that makes a style change smooth. It runs between two states, like on hover.
- CSS Animation
- Keyframes written in CSS that the browser plays. It can loop and pass through many steps.