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.
.pulse { animation: pulse 1s ease-in-out; animation-iteration-count: 3; }
Try it
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
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
::beforeand::afterpseudo-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.5stops halfway between the keyframes, at whatever the interpolation gives there. Combine withanimation-fill-mode: forwardsto keep that state. - Direction interacts with count. With
alternateand an even count the animation ends where it began; with an odd count it ends at the final keyframe. Seeanimation-direction. - Without
forwards, the element snaps back to its normal style when the last iteration ends. - Events.
animationiterationfires at the end of each cycle except the last;animationendfires after the last one. An infinite animation never firesanimationend. - 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-durationtimes the count, after the delay.
Browser support
Supported in every browser.
Related
animationโ the shorthandanimation-directionโ forward, reverse or alternating cyclesanimation-fill-modeโ styles before and after the runanimation-play-stateโ pause and resume- Lesson: Animations