Skip to content
Tutorials Center
My learning

Topics

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.

CSS
.spinner {
  animation-name: spin;
  animation-duration: 1.2s;
}

Try it

Same keyframes, different speeds

Syntax

CSS
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 ::before and ::after pseudo-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: 0 is invalid; write 0s.
  • A zero duration is not a no-op. The animation still starts and ends immediately, animationstart and animationend still fire, and animation-fill-mode applies. 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: 3 runs six seconds, plus any delay.
  • Scroll-driven animations. With animation-timeline, the duration does not control timing; the scroll position does. Leave it as auto.
  • Accessibility. Slowing a looping animation down, or turning it off, under prefers-reduced-motion: reduce is 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.