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

CSS Reference Manual

CSS @rules (RULES)

All CSS Properties

CSS3 Usage and examples of animation property

The animation CSS property is a shorthand property of the following propertiesanimation-name,animation-duration,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,animation-fill-modeandanimation-play-state.

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

Default value:none 0 ease 0 1 normal none running;
Applies to:All elements::before and::after Pseudo-element
Inheritance:None
Animatable:No.See also Animation properties.
Version: CSS3new feature
JavaScript syntax: 
object.style.animation="mymove 5s infinite"

The syntax of using animation

The syntax of this property is as follows:

animation: [ name duration timing-function delay iteration-count direction fill-mode play-state ] | initial | inherit

This example demonstrates how to use the animation property.

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

Note:At least two properties animation must be specified-name and animation-duration (greater than 0) to make the animation occur.

Attribute value

The following table describes the value of this property.

ValueDescription
animation-nameSpecify the name of the @keyframes definition to be applied to the selected element.
animation-durationSpecify the number of seconds or milliseconds required for the animation to complete one cycle.
animation-timing-functionSpecify how the animation should progress within each cycle, i.e., the easing function.
animation-delaySpecify the delay before the animation starts.
animation-iteration-countSpecify the number of times the animation should play before stopping.
animation-directionSpecify whether the animation should play in reverse in alternating cycles.
animation-fill-modeSpecify how the style should be applied to the target before and after the CSS animation is executed.
animation-play-stateSpecify whether the animation should run or pause.
initialSet this property to its default value.
inheritIf specified, the associated element uses the computed value of animation of its parent element.

Browser compatibility

Browser compatibility of the animation property, all mainstream browsers support this property. The number indicates the first browser version that supports this property.

  • 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-name,animation-duration,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,animation-fill-mode,animation-play-state,@keyframes.