CSS animation-duration Property

CSS animation-duration Property

CSS animation-duration Property


The animation-duration property defines the length of time (in seconds or milliseconds) that animation takes to complete its one cycle. Very often the animation shorthand property is used to set all animation properties at once. The default value for the animation-duration property is 0, which means that the animation starts immediately and the keyframes don’t have an effect. Negative values are invalid and they cause the property to be ignored. But they may be considered as equal to 0s by some earlier implementations.

When multiple comma-separated values are specified for any animation property, they will be attached to the animations that are defined in animation-name differently.

The animation-duration property is one of the CSS3 properties.

Initial Value0
Applies toAll elements, ::before and ::after pseudo-elements.
InheritedNo.
AnimatableNo.
VersionCSS3
DOM Syntaxobject.style.animationDuration = "4s";

Syntax

animation-duration: time | initial | inherit;

Example of the animation-duration property:

<!DOCTYPE html>
<html>
  <head>
    <style>
      .element {
        padding: 50px;
        animation: pulse 7s infinite;
      }
      @keyframes pulse {
        0% {
          background-color: #8ebf42;
        }
        50% {
          background-color: #1c87c9;
        }
        100% {
          background-color: #eee
        }
      }
    </style>
  </head>
  <body>
    <div class="element">Background of this text is animated using CSS3 animation property</div>
  </body>
</html>

Example of the animation-duration property having a duration of 6 seconds: 

<!DOCTYPE html>
<html>
  <head>
    <style>
      html,
      body {
        height: 100%;
        margin: 0;
      }
      body {
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .element {
        height: 200px;
        width: 200px;
        background-color: #1c87c9;
        animation: nudge 6s ease infinite alternate, nudge 6s linear infinite alternate;
      }
      @keyframes nudge {
        0%,
        100% {
          transform: translate(0, 0);
        }
        60% {
          transform: translate(150px, 0);
        }
        80% {
          transform: translate(-150px, 0);
        }
      }
    </style>
  </head>
  <body>
    <div class="element"></div>
  </body>
</html>

Values

ValueDescription
timeSpecifies the length of time an animation takes to cycle. This can be specified in seconds or milliseconds. The default value is 0.
initialIt makes the property use its default value.
inheritIt inherits the property from its parent's element.
Reactions

Post a Comment

0 Comments

close