CSS animation-iteration-count Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Animations & Timing

What You’ll Learn

The animation-iteration-count property controls how many times a CSS animation repeats. Use it to play an effect once, repeat it a set number of times, or loop forever with infinite.

01

Repeat Control

Set how many cycles run.

02

Syntax

Number or infinite.

03

Default 1

Plays once by default.

04

Finite Loops

Use 2, 3, or more repeats.

05

infinite

Loop without stopping.

06

Shorthand

Works inside animation too.

Definition and Usage

The animation-iteration-count CSS property defines how many times an animation cycle should play before stopping. One cycle means running through all keyframes from start to end once.

This is useful for loaders that spin forever, attention-grabbing effects that repeat a few times, or entrance animations that should happen only once.

💡
Beginner Tip

Pair animation-iteration-count: infinite with animation-direction: alternate to create smooth back-and-forth looping motion.

📝 Syntax

Set animation-iteration-count with a number or the keyword infinite:

syntax.css
selector {
  animation-iteration-count: number | infinite;
}

Basic Example

animation-iteration-count.css
.box {
  animation: move 2s ease-in-out;
  animation-iteration-count: 3;
}

Syntax Rules

  • The initial value is 1, so animations play once unless you change it.
  • Use positive numbers such as 2, 3, or decimal values like 2.5.
  • infinite repeats the animation continuously with no end.
  • When multiple animations run on one element, use comma-separated counts matching each animation.
  • Iteration count can be included in the animation shorthand after delay.

⚡ Quick Reference

QuestionAnswer
Initial value1
Applies toElements with CSS animations
InheritedNo
AnimatableNo
Common useLoaders, loops, and limited-repeat effects

Default Value

The initial value of animation-iteration-count is 1. The animation runs through its keyframes one time and then stops.

💎 Property Values

These values control how many animation cycles play.

ValueExampleMeaning
Numberanimation-iteration-count: 3;Plays the animation three full times
Decimal numberanimation-iteration-count: 2.5;Plays two full cycles, then half of the third
infiniteanimation-iteration-count: infinite;Repeats the animation forever
initialanimation-iteration-count: initial;Resets to the default value 1
inheritanimation-iteration-count: inherit;Inherits the count from the parent element
1

The pulse runs once and stops. This is the default behavior.

Single cycle

Best for one-time entrance animations.

3

The pulse repeats three times, then the animation ends.

Three cycles

Useful for short attention-grabbing effects.

infinite

The pulse keeps repeating with no end until the animation is removed.

Continuous loop

Common for spinners and loading indicators.

Finite Count vs infinite

Value typeBehaviorBest for
Number (1, 2, 3)Stops after the set number of cyclesEntrances, alerts, limited emphasis
infiniteNever stops on its ownLoaders, background motion, live indicators

👀 Live Preview

This box slides across the track 3 times, then stops:

Reload the page to watch all three cycles again. Each slide takes 1.5 seconds.

Examples Gallery

Try animation-iteration-count with a fixed repeat count, infinite, play-once behavior, and shorthand syntax.

📚 Repeat Basics

See how a numeric iteration count limits how many times an animation runs.

Example 1 — Repeat the Animation 3 Times

Move a box from left to right and repeat the animation three times before stopping.

animation-iteration-count-3.html
<style>
  @keyframes move {
    from { transform: translateX(0); }
    to { transform: translateX(300px); }
  }
  .box {
    width: 50px;
    height: 50px;
    background: blue;
    animation: move 2s ease-in-out;
    animation-iteration-count: 3;
  }
</style>

<div class="box"></div>
Try It Yourself

How It Works

Each 2-second slide is one iteration. With a count of 3, the box completes the move three times, then stops.

Example 2 — Loop Forever with infinite

Create a spinner that keeps rotating until the page changes or the animation is removed.

animation-iteration-count-infinite.css
.spinner {
  animation: spin 1s linear infinite;
}
Try It Yourself

How It Works

infinite tells the browser to repeat the spin animation continuously with no maximum count.

Example 3 — Play the Animation Once

Use the default count explicitly for a one-time fade-in effect.

animation-iteration-count-1.css
.hero-title {
  animation: fadeIn 0.8s ease-out forwards;
  animation-iteration-count: 1;
}
Try It Yourself

How It Works

A count of 1 is the default, but setting it explicitly makes one-time animations easier to read in your CSS.

⚡ Shorthand Usage

Include iteration count directly in the animation shorthand for shorter code.

Example 4 — Iteration Count in the Animation Shorthand

Add infinite after timing and delay values in the shorthand.

animation-shorthand-iteration.css
.dot {
  animation: blink 1.2s ease-in-out infinite;
}
Try It Yourself

How It Works

In animation: blink 1.2s ease-in-out infinite, the final keyword sets the iteration count to loop forever.

🧠 How animation-iteration-count Works

1

You define an animation cycle

Keyframes plus duration create one complete pass from start to end.

One cycle
2

You set an iteration count

Choose a number like 3 or the keyword infinite.

Repeat rule
3

The browser repeats the cycle

Each iteration runs the full keyframe sequence again until the count is reached.

Playback
=

Controlled repetition

You decide whether motion happens once, a few times, or continuously.

Universal Browser Support

animation-iteration-count is supported in all modern browsers alongside CSS animations.

Baseline · CSS Animations

Repeat animations reliably in modern browsers

Chrome, Firefox, Safari, Edge, and Opera all support numeric counts and infinite.

98% Modern browser support
Google Chrome43+ · Desktop & Mobile
Full support
Mozilla Firefox16+ · Desktop & Mobile
Full support
Apple Safari9+ · macOS & iOS
Full support
Microsoft Edge12+ · Modern versions
Full support
Opera30+ · Modern versions
Full support

Legacy browsers

Very old browsers without CSS animation support also lack animation-iteration-count.

💻
Internet Explorer IE 9 and earlier · No CSS animation support
None
animation-iteration-count property 98% supported

Bottom line: Use numeric counts and infinite confidently in modern projects. Avoid unnecessary infinite loops on large pages.

Conclusion

The animation-iteration-count property lets you control how many times a CSS animation repeats. It is essential for loaders, looping backgrounds, and any effect that should run once or a limited number of times.

Start with the default 1 for entrance animations, use small numbers like 2 or 3 for emphasis, and reserve infinite for ongoing indicators like spinners.

💡 Best Practices

✅ Do

  • Use 1 for one-time entrance and reveal animations
  • Use infinite for loaders and live status indicators
  • Pair infinite with animation-direction: alternate for smooth loops
  • Respect prefers-reduced-motion for accessibility
  • Keep finite repeat counts small for attention effects

❌ Don’t

  • Put infinite on every animated element in a layout
  • Forget that default 1 already plays once
  • Use infinite motion for essential content visibility
  • Confuse iteration count with animation duration
  • Leave distracting loops running after loading completes

Key Takeaways

Knowledge Unlocked

Five things to remember about animation-iteration-count

Use these points when deciding how often animations repeat.

5
Core concepts
🕑02

Default 1

Plays once by default.

Default
03

infinite

Loops without stopping.

Loop
📝04

Decimals OK

2.5 stops mid-cycle.

Values
05

Shorthand

Put infinite at the end.

Syntax

❓ Frequently Asked Questions

The animation-iteration-count property sets how many times an animation cycle repeats before stopping.
The initial value is 1, which means the animation plays once unless you set a different count or infinite.
infinite makes the animation repeat forever until it is removed or the page changes.
Yes. Values like 2.5 mean the animation completes two full cycles and then stops halfway through the third cycle.
Yes. Iteration count can be included in the shorthand, for example animation: pulse 1s ease-in-out infinite;

Practice in the Live Editor

Open the HTML editor, try animation-iteration-count: 3 or infinite, and watch the difference.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful