Short answer
Use a CSS transition for a single change between two states, and a CSS animation when you need named keyframes or repeats. MDN describes transitions as implicit: the browser fills in the frames between the start value and the end value. Animations add an author-written @keyframes list, an iteration count, and a direction, so a sequence can loop or reverse. Both have been widely available since September 2015.
Last verified against the sources listed below.
Key takeaways
- A transition runs when a property value changes, such as a hover or a script update.
- An animation can start when the element loads, and animation-iteration-count can be infinite.
- The transition shorthand is property, duration, easing, delay. The first time is duration.
- If animation-duration is omitted it defaults to 0s, so the animation is not visible.
- @keyframes from means 0 percent and to means 100 percent. Missing ends use the element's computed style.
A stylesheet choice called css transition vs animation is the difference between a change the browser interpolates and a sequence you write frame by frame. Use the transition when one state should ease into another. Use the animation when the motion has middle steps, a repeat, or a life of its own.
Both are CSS, which is the language that styles a page. The properties below are the ones MDN documents, not a preference from a design trend.
Which should you use?
Use a transition for a two-state change. Use an animation when you must name the frames or repeat them.
MDN’s transitions guide says transitions control speed when a CSS property changes. The W3C draft of 8 January 2026 calls that change an implicit transition over a duration you set.
MDN’s animations guide says an animation has two parts: a style that describes timing, and keyframes for the start, the end, and any waypoints.
| CSS transition | CSS animation | |
|---|---|---|
| Trigger | A property value changes, from a pseudo-class or from script | The animation is applied. It can start on load, after animation-delay |
| Looping | Once per change. There is no iteration count | animation-iteration-count, default 1, or infinite |
| Keyframes | None. Start and end values define the change | @keyframes, with from, to, or percentages |
| Typical use | Hover color, focus ring, a script moving a ball with transform | A slide-in, a grow and shrink, a hue cycle, an entrance that repeats |
The animated gradient generator is a fast way to see the animation side: it builds a gradient motion and gives you CSS you can read next to these rules.
What starts each effect?
A transition starts when a listed property changes. An animation starts because the animation is applied.
The transition property applies to all elements and to the ::before and ::after pseudo-elements. It is not inherited. Its initial values are a delay of 0s, a duration of 0s, transition-property of all, a timing function of ease, and transition-behavior of normal.
The special value none, the default, means no transition runs.
States come from pseudo-classes such as :hover or :active, or from JavaScript setting a style. The shorthand order is property, duration, timing function, and delay. The first time value is the duration.
The second is the delay. You can also add allow-discrete or normal for discrete behavior.
An animation’s delay is defined differently. MDN describes animation-delay as the wait between the element loading and the start of the sequence. The animation shorthand sets the name, duration, easing, delay, iteration count, direction, fill mode, play state, and timeline.
Omitted pieces use their initial values. Duration defaults to 0s, iteration count to 1, direction to normal, fill mode to none, play state to running, and the timeline to auto. The initial name is none, which means no animation.
If duration is 0s, MDN says the animation still occurs and the start and end events still fire, but the user sees no motion. Put the keyframe name last in the shorthand so a token is not parsed as a different setting.
Can the effect repeat?
A transition does not repeat by itself. An animation repeats if you set an iteration count.
Nothing in the transition properties is an iteration count. The change plays when the value changes. To play it again, change the value again, for example by leaving and re-entering :hover.
animation-iteration-count accepts a number or the keyword infinite. MDN’s slide-in example sets infinite so the motion does not stop at one pass.
Direction controls the repeat. The initial value is normal. alternate runs the next iteration backward, which is how MDN turns a one-way slide into a trip that moves back and forth.
Other documented direction values are reverse and alternate-reverse. animation-play-state can pause or run the sequence. Its initial value is running.
Fill mode decides how styles apply before and after the run. The initial value is none. Forwards is the case MDN flags for stacking: animated properties behave as if they were in will-change, and a stacking context created during the animation remains after the animation finishes.
Several animations can share one rule. Comma-separated lists line up by position. If a list is shorter than the name list, values cycle.
Extra duration values beyond the number of names are ignored. The same cycling rule is documented for transition-duration when it is shorter than transition-property.
What do keyframes add?
Keyframes are the waypoints a transition never asks you to write.
The @keyframes rule names a list of selectors and styles. from is 0 percent. to is 100 percent.
You can list percentages in any order. The browser sorts them. If you omit the start or the end, the browser uses the element’s existing computed styles for that end.
Properties that cannot be animated are ignored. Properties that can be animated still run.
If a property is missing from some keyframes, it is interpolated across the keyframes that do set it. If the same percentage is written twice, all of the specified values at that percentage are considered, and a repeated property uses the later declaration. Declarations marked important inside a keyframe are ignored.
If two @keyframes rules share a name, the last one the parser sees is used. Keyframe rules do not cascade across rule sets.
MDN gives three advantages over script-driven animation. You can make a basic animation in a few lines, with no JavaScript. The animation can keep running under moderate load, because the engine may skip frames.
The browser can also slow updates in tabs that are not visible. A transition can still smooth a script: MDN’s ball example sets transform from a click listener and lets transition: transform 1s ease the jump.
More generators for one-off CSS, including gradients and similar helpers, sit in the CSS generators collection.
Which properties are safe?
Animate properties that do not force layout on every frame, and do not animate auto.
MDN’s transitions guide says the author chooses which properties animate, and some properties are not animatable. The auto value is called out as a case to avoid. The specification recommends not animating to or from auto, and support differs: Gecko-based browsers follow that, while WebKit-based browsers are less strict.
The animation reference discourages animating box-model properties because that causes layout and repaint, and it points authors toward transform instead. The animations guide makes the same point in an example: rather than changing font-size, it wraps a word in a span, sets that span to inline-block, and scales it. Transform properties do not affect non-replaced inline content, which is why the span’s display value matters.
Discrete properties are the other special case. display and content-visibility can take part in a transition only with allow-discrete. On a transition toward display: none, the used value stays visible until the end of the duration, then flips.
On a transition away from none, it flips to the visible value at the start so the fade has something to show. Coming out of display: none also needs @starting-style, because the first style update does not start a transition by itself.
How do you limit motion?
Offer a reduced-motion path, because some motion makes people sick or makes a page unreadable.
MDN’s animation reference says blinking and flashing can be a problem for people with cognitive conditions such as ADHD, and that some motion can trigger vestibular disorders, epilepsy, migraine, and scotopic sensitivity. It tells authors to provide a way to pause or disable animation, and to use the reduced-motion media query for people who have asked for less motion.
WCAG 2.2.2 says motion that starts by itself, lasts more than five seconds, and sits beside other content needs a pause, stop, or hide control, unless that motion is essential.
WebKit’s note documents prefers-reduced-motion for that switch, in a media query or in script. The animations draft is where repeat count and repeating behavior are specified.
If the only goal is “this button should not snap,” you do not need keyframes. If the goal is “this mark should travel, grow, and repeat,” a transition has no place to put the middle frame or the repeat count.
Frequently asked questions
What does the transition shorthand do with two time values?
MDN's transition reference says the first time that can be parsed is the duration and the second is the delay. Both default to 0s when omitted. A declaration such as background-color 2s 500ms therefore waits half a second, then spends two seconds changing the color. The same order applies inside the animation shorthand: the first time is animation-duration and the second is animation-delay. Putting the name last in the animation shorthand avoids the name being read as some other value.
Which transition events fire, and when?
MDN documents transitionrun, which fires before any delay, transitionstart, which fires after the delay, and transitionend, which fires when the transition finishes. The end event does not fire if the transition is aborted because the element is set to display none or the animated property changes again before completion. The event object exposes propertyName and elapsedTime. Elapsed time is not affected by transition-delay. A listener on transitionend is the hook for a script that should run only after the change has visually finished.
What are animationstart, animationend, and animationiteration?
MDN's animations guide says these events report when an animation starts, when it finishes, and when a new iteration begins. Each event carries the elapsed time and the animation name. After the final iteration, animationiteration is not sent. animationend is sent instead. If you set the animating class from script after the listener is attached, you can observe the start. If the class is already present when the script runs, the start may have happened already. A duration of 0s still fires the start and end events, with nothing visible.
Why does display need allow-discrete?
MDN says display and content-visibility can transition only as a discrete animation, and the transition list needs transition-behavior allow-discrete. Discrete properties normally flip halfway through. The exception is display none or content-visibility hidden: the browser keeps the element shown for the whole duration, flipping to none at 100 percent on the way out and to the visible value at 0 percent on the way in. Entering from display none also needs @starting-style, because a transition does not run on the element's first style update.
What if two animations set the same property?
MDN's animation reference says that when two animations set different values of the same property, the one declared later in the cascade wins. In the sunrise and bounce example, both set transform, and the later animation's transform is the one that runs. The earlier animation is still declared. Its conflicting property is overridden. If you need both motions, put them in one keyframe list, or animate different properties, such as translate on one animation and filter on another.
Sources
- Using CSS transitions · MDN, 2026
- Using CSS animations · MDN, 2026
- transition CSS property · MDN, 2026
- animation CSS property · MDN, 2026
- @keyframes CSS at-rule · MDN, 2026
- CSS Transitions Module Level 1 · W3C, 2026
- CSS Animations Module Level 1 · CSS Working Group, 2026
- Understanding SC 2.2.2 Pause, Stop, Hide · W3C, 2026
- Responsive Design for Motion · WebKit, 2017