Computer >> Computer tutorials >  >> Programming >> CSS

Set how many times an Animation should run with CSS


Use the animation-iteration-count property to set how many times the animation should run with CSS.

The following example sets the count of animation to 2:

Example

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
            width: 150px;
            height: 200px;
            background-color: yellow;
            animation-name: myanim;
            animation-duration: 2s;
            animation-iteration-count: 2;
         }
         @keyframes myanim {
         from {
            background-color: green;
         }
         to {
               background-color: blue;
            }
         }
      </style>
   </head>

   <body>
      <div> </div>
   </body>
</html>