CSS animation-play-state

The CSS animation-play-state property is used to pause or play an animation. For example:

HTML with CSS Code
<!DOCTYPE html>
<html>
<head>
   <style>
      #mydiv {width: 50px; height: 50px; border-radius: 50%;
         background-color: maroon; position: relative;
         animation-name: codescracker; animation-duration: 2s; animation-iteration-count: infinite;}
      @keyframes codescracker {
         from {top: 0px; left: 0px;}
         to {top: 0px; left: 220px;}
      }
      #mydiv:hover{animation-play-state: paused;}
   </style>
</head>
<body>

   <div id="mydiv"></div>
   
</body>
</html>
Output

When you hover the mouse cursor on the moving circle, then animation get paused.

Note - The animation-name is used to define a name for an animation.

Note - The animation-duration is used to define time to complete one iteration or cycle of an animation.

Note - The animation-iteration-count is used to define the total number of iterations or cycles for an animation to play.

Note - The @keyframes is used to define the change in styles for multiple times in one cycle of selected animation.

CSS animation-play-state Syntax

The syntax of animation-play-state property in CSS, is:

animation-play-state: x;

The value of x should be any of the following:

  • paused - used to pause the animation
  • running - used to start the animation. This is the default value
  • initial - used to use the default value
  • inherit - used to use the value inherited by the parent element

CSS Online Test


« Previous Tutorial Next Tutorial »



Like/Share Us on Facebook 😋