CSS animation-iteration-count Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The animation-iteration-count property sets how many times an animation cycle plays before it stops. The initial value is 1. Use a number for a fixed count, or infinite to keep repeating.

Non-integer numbers play a partial cycle. For example, 1.5 runs one full play, then half of the next. You still need an animation-name and an animation-duration. It applies to all elements, including ::before and ::after, and it is not inherited. A count does not remove motion for someone who set prefers-reduced-motion.

Standard-track.

Not deprecated and not experimental. Numbers and infinite have been widely available since 2015.

CSS Syntax

syntax.css
animation-iteration-count: 1 | 2 | 1.5 | infinite | initial | inherit;

The initial value is 1. Zero or a positive number is allowed. Negative numbers are invalid. For several animations, separate the counts with commas, in the same order as the names.

Property Values

ValueDescriptionTry it
1Plays one cycle. This is the initial valueTry it
2Plays two full cycles, then stopsTry it
1.5One full cycle, then half of the next cycleTry it
infiniteRepeats foreverTry it
initialSets this property to its default value, 1Try it
inheritInherits this property from the parent elementTry it

How to Use animation-iteration-count

Name a short fade, give it a duration, then set how many times it should play.

  1. Write @keyframes fade from full opacity to 0.25.
  2. Set animation-name: fade and animation-duration: 1s.
  3. Set animation-iteration-count to a number or infinite.
  4. Use at least 2 when you want to see animation-direction: alternate turn around.
PieceRequired?Role
A named animationYesA count has nothing to repeat without @keyframes
A durationYesEach play needs a length of time
A count or infiniteYes1 is the initial value

Live Preview

The same one-second fade. Only animation-iteration-count changes. Apply again to restart.

1 plays once. 2 plays twice. 1.5 stops halfway through the second play.

Result

Fade

animation-iteration-count: 1. One cycle, then it stops.

CSS Examples

Each snippet uses the same fade. The only change is animation-iteration-count. Use Try It Yourself for a live editor.

Example 1 — Play Twice

The fade runs two full cycles, then stops.

CSS
<style>
  @keyframes fade {
    from {
      opacity: 1;
    }

    to {
      opacity: 0.25;
    }
  }

  p {
    animation-name: fade;
    animation-duration: 1s;
    animation-iteration-count: 2;
  }
</style>

<p>Fade</p>
Try It Yourself

How It Works

  1. Name the steps. fade goes from opacity 1 to 0.25.
  2. Set one second per play. animation-duration: 1s is the length of each cycle.
  3. Ask for two plays. animation-iteration-count: 2 runs the fade, then runs it again.
  4. Then stop. After the second play, the animation ends and the word returns to its normal style.

Example 2 — Loop Forever

The same fade keeps starting over.

CSS
<style>
  @keyframes fade {
    from {
      opacity: 1;
    }

    to {
      opacity: 0.25;
    }
  }

  p {
    animation-name: fade;
    animation-duration: 1s;
    animation-iteration-count: infinite;
  }
</style>

<p>Fade</p>
Try It Yourself

How It Works

  1. Keep the same fade. One second from full opacity to a quarter.
  2. Remove the stop. infinite means there is no final play.
  3. Watch the jump. Each new play starts at the first keyframe again, unless you also set animation-direction: alternate.
  4. No after state. Because it never finishes, animation-fill-mode: forwards has nothing to keep.

Example 3 — One and a Half

One full fade, then the second fade stops halfway.

CSS
<style>
  @keyframes fade {
    from {
      opacity: 1;
    }

    to {
      opacity: 0.25;
    }
  }

  p {
    animation-name: fade;
    animation-duration: 1s;
    animation-iteration-count: 1.5;
  }
</style>

<p>Fade</p>
Try It Yourself

How It Works

  1. Use the same one-second fade. Full opacity down to a quarter.
  2. Play one full cycle. The first second runs from from to to.
  3. Start a second cycle. The count still has 0.5 left, so a new play begins.
  4. Stop halfway. At half of that second play, the animation ends. Non-integer counts are for partial cycles.

Edge Cases & Pitfalls

If the loop seems wrong, check the count, the direction, and the shorthand.

once

Default is one play

If you forget this property, the count is 1. alternate then never shows its reverse play.

minus

Negative counts are invalid

animation-iteration-count: -1 is dropped. Use 0, a positive number, or infinite.

end

infinite never finishes

animation-fill-mode: forwards needs a finished play. An endless loop has no after state to keep.

order

The shorthand can wipe the count

animation: 1s fade sets this property back to 1. Write animation-iteration-count after it, or include the number or infinite in the shorthand.

list

One count per animation name

animation-iteration-count: 2, infinite follows the order of animation-name. Fewer counts than names, and the list repeats.

Browser Support

animation-iteration-count is a browser style property. Node.js, Deno, and Bun do not play it. The versions below include numbers and infinite.

✓ Baseline · Widely available since 2015

animation-iteration-count

Chrome 43+, Firefox 16+, Safari 9+, Edge 12+, Internet Explorer 10+. Integer counts, fractions, and infinite share these versions.

97% numbers and infinite
Google Chrome 43+
Full support
Mozilla Firefox 16+
Full support
Apple Safari 9+
Full support
Microsoft Edge 12+
Full support
Opera 30+
Full support
Samsung Internet 4+
Full support
Internet Explorer 10+
Full support
animation-iteration-count Widely supported

Bottom line: Older Chrome, Safari, and Firefox also accepted a prefixed property. Fractional counts and infinite shipped with CSS animations.

Key Takeaways

  • Role: how many times one animation cycle plays.
  • 1: the initial value. One play, then stop.
  • infinite: never stops. Useful for loaders and loops.
  • Fractions: 1.5 plays one full cycle, then half of the next.

One line: set a name and a duration, then animation-iteration-count decides how many cycles run.

Frequently Asked Questions

It sets how many times an animation cycle plays before stopping. 1 plays once. 2 plays twice. infinite keeps repeating.
The initial value is 1. The animation plays one cycle unless you set another number or infinite.
Yes. Non-integer values play a partial cycle. 1.5 means one full play, then half of the next play, then it stops.
The animation repeats forever until the style is removed or the page changes. It never reaches a finished after state for animation-fill-mode: forwards.
No. Negative numbers are invalid and the declaration is ignored. Use 0 or a positive number, or infinite.
Chrome 43+, Firefox 16+, Safari 9+, Edge 12+, and Internet Explorer 10 support numbers and infinite. It is a browser style property, not a Node.js feature.

Next: animation-name

Choose which @keyframes rule each count should play.

animation-name tutorial →

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.

8 people found this page helpful