Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Transforms, Transitions and Animations

The animation-iteration-count property

Reference for the CSS animation-iteration-count property: run an animation once, several times, partly or forever with infinite, with syntax and live examples.

The animation-iteration-count property sets how many times an animation cycle plays. The default is 1. You can use whole numbers, fractions (to stop part of the way through a cycle) or the keyword infinite to loop for as long as the animation applies.

CSS
.pulse {
  animation: pulse 1s ease-in-out;
  animation-iteration-count: 3;
}

Try it

1, 3, 2.5 and infinite

With alternate, each pass reverses direction. The 3 dot ends at the right side after three passes (right, left, right); the 2.5 dot stops half way through its third pass; the infinite dot never stops.

Syntax

CSS
animation-iteration-count: [ infinite | <number [0,โˆž]> ]#

/* examples */
animation-iteration-count: 3;
animation-iteration-count: 0.5;
animation-iteration-count: infinite;
  • Initial value: 1
  • Applies to: all elements, and the ::before and ::after pseudo-elements
  • Inherited: no
  • Animatable: no
  • Computed value: as specified

Values

Value Description
<number> A non-negative number. 2 plays twice; 1.5 plays one and a half cycles. Negative values are invalid.
infinite Repeats forever.
0 The animation runs zero times (it effectively ends immediately; fill mode can still apply).
Comma-separated list One count per name in animation-name.

Usage notes

  • Fractions stop mid-cycle. 0.5 stops halfway between the keyframes, at whatever the interpolation gives there. Combine with animation-fill-mode: forwards to keep that state.
  • Direction interacts with count. With alternate and an even count the animation ends where it began; with an odd count it ends at the final keyframe. See animation-direction.
  • Without forwards, the element snaps back to its normal style when the last iteration ends.
  • Events. animationiteration fires at the end of each cycle except the last; animationend fires after the last one. An infinite animation never fires animationend.
  • Performance. Infinite animations keep the compositor and sometimes the CPU busy. Pause them when they are off screen or when the tab is hidden, and avoid animating layout properties.
  • Accessibility. Content that loops forever is a problem for people who are distracted by motion. Prefer a finite count for decoration, and honor prefers-reduced-motion. Anything that moves for more than five seconds should be pausable.
  • Cycle time. Total time is animation-duration times the count, after the delay.

Browser support

Supported in every browser.