
How to Play Animations Infinitely in CSS
In order to play CSS animations indefinitely, all you have to do is set the animation-iteration-count
property to infinite
.
Copied to clipboard! Playground
@keyframes rotate {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.loading-circle {
/* We need βlinearβ for smooth transition */
animation: rotate 2s linear;
animation-iteration-count: infinite;
}
Make sure that you return to the initial state in order to create a smooth animation. You can also set an arbitrary number as the iteration count to repeat the animation a number of times.
Copied to clipboard!
/* This will play the animation twice */
.animation {
animation-iteration-count: 2;
}
You can also use a shorthand property, where you can define the animation-iteration-count
as the very last rule:
Copied to clipboard!
.loading-circle {
animation: rotate 2s linear infinite;
}


Resources:
π More Webtips
Master the Art of Frontend
Access exclusive interactive lessons
Unlimited access to hundreds of tutorials
Remove ads to learn without distractions
Courses

CSS - The Complete Guide (including Flexbox, Grid and Sass)
Including Flexbox, Grid, and Sass
Whether you're learning CSS for the first time or brushing up on your CSS skills and diving even deeper, this course is for you. Every web developer has to know CSS.

The HTML & CSS Bootcamp
From Zero to Expert!
This course covers flexbox, CSS grid, animations, responsive design, and much more! You will find tons of exercises & projects inside this course.

The Creative HTML5 & CSS3 Course
Build Awesome Websites
Learn HTML5 and CSS3 by creating three amazing, well-designed and animated websites from scratch.