CSS animation-duration

The CSS animation-duration property is used to define the time to complete one iteration or cycle of animation. For example:

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

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

Note - Since the default value of animation-duration is 0. Therefore, be sure to define the animation-duration property to play the animation.

Note - The animation-name is used to define a name for 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-duration Syntax

The syntax of animation-duration property in CSS, is:

animation-duration: x;

The value of x should be any of the following:

CSS Online Test


« Previous Tutorial Next Tutorial »


Liked this post? Share it!