English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules (RULES)

Comprehensive list of CSS properties

CSS3 animation-Usage and examples of the duration attribute

CSS3 animation-The duration attribute specifies the number of seconds (s) or milliseconds (ms) the animation should take to complete one cycle.

The following table summarizes the usage context and version history of this attribute.

Default Value:0s
Applies to:All elements ::before and ::after Pseudo-element
Inheritance:None
Animated by:No.Please see Animation Properties.
Version: CSS3new feature
JavaScript Syntax:    
object    object.style.animationDuration="3s"

animation-Syntax of duration usage

The syntax of this attribute is as follows:

animation-duration: time | initial | inherit

The following example demonstrates how to use animation-duration Attribute.

.box {
    width: 50px;
    height: 50px;
    background: red;
    position: relative;
    /* Chrome, Safari, Opera */
    -webkit-animation-name: moveit;
    -webkit-animation-duration: 2s;
    
    animation-name: moveit;
    animation-duration: 2s;
}
 
/* Chrome, Safari, Opera */
@-webkit-keyframes moveit {
    from {left: 0;}
    to {left: 50%;}
}
 
@keyframes moveit {
    from {left: 0;}
    to {left: 50%;}
}
Test and See‹/›

Attribute Value

The following table describes the value of this attribute.

ValueDescription
timeSpecify the time required for the animation to complete one cycle. The default value is 0s. Negative values are invalid.
initialSet this attribute to its default value.
inheritIf specified, the associated element adopts its parent element's animation-Calculation Value of duration Attribute.

Browser Compatibility

animation-Browser Compatibility of duration Attribute, all mainstream browsers support this attribute.

  • Firefox 5+ -moz-,15 +

  • Google Chrome 4+ -webkit-

  • Internet Explorer 10+

  • Apple Safari 4+ -webkit-

  • Opera 12+ -o-,15+ -webkit-

Further Reading

Please refer to the following tutorials:CSS3Animation.

Related Properties and Rules:animation,animation-name,animation-duration,animation-timing-function,animation-iteration-count,animation-duration,animation-fill-mode,animation-play-state,@keyframes.