CSS propertyAnimations
animation-iteration-count
Sets how many times the animation repeats.
- Initial value
1- Inherited
- No
- Animatable
- no
- Applies to
- all elements and the ::before and ::after pseudo-elements
- JavaScript
element.style.animationIterationCount = "infinite"
Example
#CSS
.new-message {
animation: ring 0.4s ease-in-out 3;
}Example HTML
<style>@keyframes ring2 { 25% { rotate: 15deg; } 75% { rotate: -15deg; } }</style>
<p style="margin: 0;"><span style="display: inline-block; animation: ring2 .4s ease-in-out 3;">π</span> You have a new message from your mentor</p>Preview
Definition and usage
#The animation-iteration-count property sets the number of animation runs. By default the animation plays once. You can provide any number, or infinite to loop it forever.
Fractions are also allowed: 0.5 plays half of the animation and stops in the middle.
Together with animation-direction: alternate, each following run goes in the opposite direction, so two runs produce a back-and-forth movement.
Syntax
#Syntax
animation-iteration-count: infinite | <number> [, β¦]*;Values
#Values in practice
#1
The bell shakes once.
.demo { animation-iteration-count: 1; }3
Three shakes in a row.
.demo { animation-iteration-count: 3; }infinite
The bell rings nonstop.
.demo { animation-iteration-count: infinite; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- Animate notifications and highlights a few times, not forever. Constant motion quickly becomes annoying.
- Reserve
infinitefor states that really last, such as loading.
Related entries
#Practise it in lessons
#Spotted a mistake or missing an example? Write to us.