CSS propertyAnimations

animation-iteration-count

Sets how many times the animation repeats.

Initial value
1
Inherited
No
Animatable
no
Applies to
all elements and the ::before and ::after pseudo-elements
JavaScript
element.style.animationIterationCount = "infinite"
On this page

Example

#
CSS
.new-message {
  animation: ring 0.4s ease-in-out 3;
}
Preview

Definition and usage

#

The animation-iteration-count property sets the number of animation runs. By default the animation plays once. You can provide any number, or infinite to loop it forever.

Fractions are also allowed: 0.5 plays half of the animation and stops in the middle.

Together with animation-direction: alternate, each following run goes in the opposite direction, so two runs produce a back-and-forth movement.

Syntax

#
Syntax
animation-iteration-count: infinite | <number> [, …]*;

Values

#
  • 1

    The bell shakes once.
  • 3

    Three shakes in a row.
  • infinite

    The bell rings nonstop.

Values in practice

#

1

The bell shakes once.
.demo { animation-iteration-count: 1; }

3

Three shakes in a row.
.demo { animation-iteration-count: 3; }

infinite

The bell rings nonstop.
.demo { animation-iteration-count: infinite; }

Browser support

#

Widely available

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

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Animate notifications and highlights a few times, not forever. Constant motion quickly becomes annoying.
  • Reserve infinite for states that really last, such as loading.

Related entries

#

Practise it in lessons

#

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