CSS Reference ยท Transforms, Transitions and Animations
The animation-duration property
Reference for the CSS animation-duration property: set how long one cycle of a keyframe animation takes, with syntax, values, live examples and support.
The animation-duration property sets how long one cycle of an animation takes, from its first keyframe to its last. With repeats, the total running time is the duration multiplied by the iteration count.
The default is auto, which for an ordinary time-based animation means 0s, so an animation with a name but no duration shows nothing and finishes at once.
.spinner { animation-name: spin; animation-duration: 1.2s; }
Try it
Syntax
animation-duration: [ auto | <time [0s,โ]> ]# /* examples */ animation-duration: 2s; animation-duration: 350ms; animation-duration: 1s, 3s;
- Initial value:
auto - Applies to: all elements, and the
::beforeand::afterpseudo-elements - Inherited: no
- Animatable: no
- Computed value: as specified (for
auto, the keyword)
Values
| Value | Description |
|---|---|
<time> |
A non-negative time with a unit: s or ms. Negative values make the declaration invalid. |
auto |
For time-based animations it behaves as 0s. It exists so that scroll-driven animations can fill the timeline. |
| Comma-separated list | One duration per name in animation-name. |
Usage notes
- A unit is required.
animation-duration: 0is invalid; write0s. - A zero duration is not a no-op. The animation still starts and ends immediately,
animationstartandanimationendstill fire, andanimation-fill-modeapplies. This is occasionally used to set a final state through keyframes. - Scale to distance and importance. Small movements read well at 150 to 300 ms; large or decorative movements may need a second or more. Loading spinners usually take about a second per turn.
- Total time. A 2s animation with
animation-iteration-count: 3runs six seconds, plus any delay. - Scroll-driven animations. With
animation-timeline, the duration does not control timing; the scroll position does. Leave it asauto. - Accessibility. Slowing a looping animation down, or turning it off, under
prefers-reduced-motion: reduceis a kind and simple adjustment.
Browser support
Supported in every browser. The auto keyword matters for newer scroll-driven features; check a compatibility table for those.
Related
animationโ the shorthandanimation-delayโ waits before startinganimation-iteration-countโ how many cyclestransition-durationโ the same idea for transitions- Lesson: Animations