Skip to content
Related Articles

Related Articles

How to play the animation exactly two times using CSS ?

Improve Article
Save Article
  • Last Updated : 23 Sep, 2020
Improve Article
Save Article

The approach of this article is to play the animation exactly two times by using the animation-iteration-count property in CSS. It is used to specify the number of times the animation will be repeated. It can specify as infinite to repeat the animation indefinitely.  


animation-iteration-count: number | infinite | initial | inherit; 

Example: Below code used to change the background color of <h2> element from red to blue. 


<!DOCTYPE html> 
        .geeks { 
            font-size: 40px; 
            font-family:Times New Roman; 
        .geeks1 { 
            font-family:Times New Roman; 
        #one { 
            animation-name: example; 
            animation-duration: 2s; 
            /* Animation will be repeated twice */ 
            animation-iteration-count: 2; 
        @keyframes example { 
            from { 
                background-color: red; 
            to { 
                background-color: blue 
    <div class = "geeks"
    <div class = "geeks1"
        A computer science portal for geeks 
    <!-- Animation of the text inside the 
        h2 tag below will be repeated twice only -->
    <h2 id="one"
        How to play the animation 
        two times using CSS? 


Supported Browsers:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!