Course contentsShow
← Web Development
Lesson 515 of 2,9829. CSS Transitions and AnimationsFree lesson

The animation-duration Property

Control how long an animation takes to complete one cycle using time units.

The animation-duration Property

What you'll learn: How to control the length of time a CSS animation takes to complete one full cycle.


While animation-name tells the browser which animation to run, animation-duration controls how long that animation takes to complete from start to finish. Without setting a duration, your animation won't run at all—the default is 0s (zero seconds).

Understanding animation-duration

Think of animation-duration like setting a timer for a performance. If a dancer performs a routine, the duration determines whether they complete it in 5 seconds or 5 minutes. The same choreography (keyframes) can be performed quickly or slowly depending on this property.

The animation-duration property accepts time values in two units:

  • Seconds: s (e.g., 2s, 0.5s, 3.75s)
  • Milliseconds: ms (e.g., 2000ms, 500ms, 3750ms)

Syntax

.element {
  animation-name: slidein;
  animation-duration: 2s; /* Takes 2 seconds to complete */
}

You can use decimal values for precision:

.quick {
  animation-duration: 0.3s; /* 300 milliseconds */
}

.slow {
  animation-duration: 4.5s; /* Four and a half seconds */
}

Practical Considerations

Longer durations create slower, more dramatic animations. Shorter durations feel snappier and more energetic. A subtle fade might use 0.2s, while a complex transformation could take 2s or more.

Key Takeaway: The animation-duration property defines how long one complete cycle of a keyframe animation takes, using seconds (s) or milliseconds (ms)—without it, animations won't play.