CSS propertyAnimations

animation-duration

Sets how long one animation cycle takes.

Initial value
0s
Inherited
No
Animatable
no
Applies to
all elements and the ::before and ::after pseudo-elements
JavaScript
element.style.animationDuration = "2s"
On this page

Example

#
CSS
.progress {
  animation: fill 2.5s ease-out forwards;
}

@keyframes fill {
  from { width: 0; }
  to { width: 72%; }
}
Preview

Definition and usage

#

The animation-duration property sets the time of a single run of the animation, from the first to the last keyframe. You provide it in seconds or milliseconds.

The default is zero, so an animation with only a name will not be visible. This is the most common reason an animation β€œdoes not work”.

With multiple iterations, the total animation time is the duration multiplied by the iteration count. The delay counts only once, before the first cycle.

Syntax

#
Syntax
animation-duration: <time> [, <time>]*;

Values

#
  • 0.4s

    Fast movement back and forth.
  • 1.5s

    A moderate pace.
  • 4s

    Slow, calm movement.

Values in practice

#

0.4s

Fast movement back and forth.
.demo { animation-duration: 0.4s; }

1.5s

A moderate pace.
.demo { animation-duration: 1.5s; }

4s

Slow, calm movement.
.demo { animation-duration: 4s; }

Browser support

#

Widely available

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • If an animation does not start, first check that it has a duration greater than zero.
  • Entrance effects usually last 300-600 ms. Longer ones delay access to the content.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.