CSS animation-iteration-count Property
The animation-iteration-count property specifies how many times a CSS keyframe animation plays.
It accepts non-negative numbers, including fractional values, or the keyword infinite. This property is useful for animations that should run once, repeat a fixed number of times, or continue indefinitely.
animation-iteration-count Syntax
selector {
animation-iteration-count: 3;
}
Specify a non-negative number to control the number of iterations, or use infinite to repeat the animation indefinitely.
.once {
animation-iteration-count: 1;
}
.three-times {
animation-iteration-count: 3;
}
.partial {
animation-iteration-count: 2.5;
}
.continuous {
animation-iteration-count: infinite;
}
For multiple animations, specify a comma-separated list of iteration counts.
.multiple {
animation-iteration-count: 1, 3, infinite;
}
The property also accepts the global CSS values inherit, initial, revert, revert-layer, and unset.
Property Values
| Value | Description |
|---|---|
1 |
Plays the animation once. This is the initial value. |
0 |
Specifies zero iterations, so the animation has no active playback duration. |
3 |
Plays the animation three times. |
2.5 |
Plays two complete iterations and half of a third iteration. |
infinite |
Repeats the animation indefinitely while it remains active. |
1, 3 |
Assigns separate iteration counts to multiple animations. |
The property accepts non-negative CSS <number> values or infinite. Negative numbers are invalid, and iteration counts do not use time units.
The property applies to all elements, is not inherited, and has an initial value of 1. Its computed value is the specified list of numbers or infinite keywords.
The animation-iteration-count property itself is not animatable.
How animation-iteration-count Works
One iteration is a single playback cycle through an animation's keyframes. The animation-iteration-count property determines how many of these cycles occur.
@keyframes move-box {
from {
transform: translateX(0);
}
to {
transform: translateX(100px);
}
}
.box {
animation-name: move-box;
animation-duration: 2s;
animation-timing-function: linear;
animation-iteration-count: 3;
}
In this example, each iteration lasts two seconds. With an iteration count of 3, the animation has a total active duration of six seconds.
Because the animation uses the default direction of normal, it returns to its starting keyframe at the beginning of each new iteration.
The iteration count does not change the duration of an individual cycle. It determines how many cycles occur before the animation finishes.
Finite and Infinite Iterations
Use a finite iteration count when an animation should finish after a specific number of cycles. Use infinite when it should continue repeating.
Finite Iterations
.notification {
animation: pulse 1s ease-in-out 3;
}
The notification completes three animation cycles and then finishes. Its appearance afterward depends on animation-fill-mode and its underlying styles.
Infinite Iterations
.loading-indicator {
animation: spin 1s linear infinite;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
The loading indicator continuously rotates as long as the animation remains active.
An infinite animation can still be paused, removed, or interrupted. The infinite keyword does not prevent other CSS rules or scripts from changing its playback behavior.
Zero Iterations
.disabled-animation {
animation: pulse 1s ease 0;
}
An iteration count of 0 produces no active animation cycles. Depending on the fill mode and delay, the animation may still apply a boundary keyframe effect.
Fractional Iteration Counts
Iteration counts do not have to be whole numbers. A fractional value allows an animation to stop partway through its final cycle.
.box {
animation: move-box 2s linear 2.5 forwards;
}
This animation completes two full iterations and then progresses halfway through a third iteration.
With a two-second duration, its total active duration is five seconds.
| Iteration Count | Playback Behavior |
|---|---|
0.5 |
Plays half of one iteration. |
1.5 |
Plays one full iteration and half of the next. |
2.25 |
Plays two full iterations and one-quarter of the next. |
3.75 |
Plays three full iterations and three-quarters of the next. |
The final visual state also depends on animation-direction and animation-timing-function. For example, halfway through a reversed iteration may produce a different result from halfway through a forward iteration.
Use animation-fill-mode: forwards when the element should retain the final partial-iteration effect after playback finishes.
Iteration Count and Animation Direction
The animation-direction property determines whether each iteration plays forward, backward, or alternates between the two.
When combined with animation-iteration-count, it controls how many forward and reverse cycles occur.
.box {
animation: move-box 2s ease-in-out 4 alternate;
}
This animation completes four iterations:
- First iteration: forward.
- Second iteration: backward.
- Third iteration: forward.
- Fourth iteration: backward.
Using alternate allows the element to travel back and forth without jumping to its starting position at each iteration boundary.
With alternate-reverse, the first iteration plays backward, the second forward, and subsequent iterations continue alternating.
For a finite alternating animation, the final position depends on whether the last iteration ends at the beginning or end of the keyframe sequence.
Multiple Animation Iteration Counts
When an element runs several animations, you can assign a separate iteration count to each one.
.animated-element {
animation-name: fade-in, rotate;
animation-duration: 1s, 2s;
animation-iteration-count: 1, infinite;
}
The fade-in animation plays once, while the rotate animation repeats indefinitely.
Iteration counts are matched to animations in the order specified by animation-name.
If fewer iteration counts are provided than animations, the browser repeats the list as needed.
.three-animations {
animation-name: fade, move, rotate;
animation-iteration-count: 1, 3;
}
Here, fade plays once, move plays three times, and rotate plays once.
This makes it possible to combine a one-time entrance effect with another animation that continues running.
animation-iteration-count Example
The following example compares four iteration counts. Each square moves horizontally using the same keyframes and two-second duration.
<div class="iteration-demo">
<div class="iteration-row">
<strong>1</strong>
<div class="iteration-track"><div class="iteration-box once"></div></div>
</div>
<div class="iteration-row">
<strong>2</strong>
<div class="iteration-track"><div class="iteration-box twice"></div></div>
</div>
<div class="iteration-row">
<strong>2.5</strong>
<div class="iteration-track"><div class="iteration-box partial"></div></div>
</div>
<div class="iteration-row">
<strong>infinite</strong>
<div class="iteration-track"><div class="iteration-box continuous"></div></div>
</div>
</div>
.iteration-demo {
display: grid;
gap: 12px;
}
.iteration-row {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
.iteration-row strong {
flex: 0 0 65px;
}
.iteration-track {
flex: 1 1 140px;
min-width: 0;
height: 40px;
padding: 5px;
background-color: #f1f3f5;
border: 1px solid #ccc;
box-sizing: border-box;
}
.iteration-box {
width: 30px;
height: 28px;
background-color: #1769aa;
animation-name: iteration-move;
animation-duration: 2s;
animation-timing-function: linear;
animation-direction: alternate;
animation-fill-mode: forwards;
}
.iteration-box.once {
animation-iteration-count: 1;
}
.iteration-box.twice {
animation-iteration-count: 2;
}
.iteration-box.partial {
animation-iteration-count: 2.5;
}
.iteration-box.continuous {
animation-iteration-count: infinite;
}
@keyframes iteration-move {
from {
transform: translateX(0);
}
to {
transform: translateX(100px);
}
}
@media (prefers-reduced-motion: reduce) {
.iteration-box {
animation: none;
}
}
The animations use alternate to reverse direction between iterations. The forwards fill mode retains the ending position of each finite animation.
The square set to 1 finishes at the right end of its path after two seconds. The square set to 2 returns to the left after four seconds.
The 2.5 square stops halfway through its third iteration after five seconds, while the infinite square continues moving back and forth.
The example runs when the page loads. Reload the page to observe the finite animations again. If reduced motion is enabled, all squares remain stationary.
Duration and Fill Mode
The total active duration of a finite, time-based animation is determined by its iteration count and the duration of each iteration.
For example:
.box {
animation-name: move-box;
animation-duration: 2s;
animation-iteration-count: 3;
animation-fill-mode: forwards;
}
Each iteration lasts two seconds, so three iterations produce six seconds of active animation.
The forwards fill mode retains the appropriate ending keyframe effect after the final iteration.
| Duration | Iteration Count | Total Active Duration |
|---|---|---|
1s |
3 |
3 seconds |
2s |
4 |
8 seconds |
500ms |
5 |
2.5 seconds |
2s |
2.5 |
5 seconds |
An animation-delay can add waiting time before the active period begins. A negative delay can make the animation begin partway through its progress.
For an infinite animation, there is no finite total active duration, and the animation does not normally enter its after phase while it continues running.
Important Considerations
Keep the following points in mind when using animation-iteration-count:
- Default value: The initial value is
1, so animations play once unless another count is specified. - Fractional values: Non-integer counts are valid and allow animations to finish partway through a cycle.
- Negative values: Negative iteration counts are invalid and cause the declaration to be ignored.
- Infinite playback: The
infinitekeyword repeats an animation continuously until it is paused, removed, or otherwise interrupted. - Direction: Use
alternateoralternate-reverseto reverse playback between iterations. - Fill mode: Use
animation-fill-modeto control the appearance of an element after a finite animation finishes. - Shorthand declarations: The
animationshorthand can specify iteration count directly, as inanimation: pulse 1s ease 3;. - Accessibility: Avoid unnecessary continuous motion and respect the
prefers-reduced-motionmedia feature.
Use a finite count for temporary visual effects and infinite only when continuous animation serves a clear purpose, such as indicating ongoing activity.
Browser Support
The animation-iteration-count property has Baseline Widely available status and is supported in modern browsers, including Chrome, Edge, Firefox, and Safari.
Finite numbers, fractional counts, and the infinite keyword are broadly supported. Older browser versions may require vendor-prefixed animation properties.
Visit Can I Use? to check current browser compatibility.
Specifications
The animation-iteration-count property is defined in the CSS Animations Level 1 specification.
