Stopping and Starting Animations

You can stop and resume an animation through the animation-play-state property.

            #myID { 
                padding: 5px; 
                border: medium double black; 
                background-color: lightgray; 
            #myID { 
                -webkit-animation-duration: 5000ms; 
                -webkit-animation-iteration-count: infinite; 
                -webkit-animation-direction: alternate; 
                -webkit-animation-timing-function: linear; 
                -webkit-animation-name: 'GrowShrink'; 
            @-webkit-keyframes GrowShrink { 
                from { 
                    font-size: large; 
                    border: medium solid black; 
                to { 
                    font-size: x-large; 
                    border: medium solid white; 
                    background-color: green; 
                    color: white; 
                    padding: 4px; 
        <p id="myID"> 
            <span id="myID">CSS</span>
            var buttons = document.getElementsByTagName("BUTTON"); 
            for (var i = 0; i < buttons.length; i++) { 
                buttons[i].onclick = function(e) { 
                    document.getElementById("myID").style.webkitAnimationPlayState = 
Click to view the demo
  HTML CSS Book 

  1. CSS animations defines how to move from one CSS style to another.
  2. Reusing Key Frames
  3. Stopping and Starting Animations