The numbers in the table specify the first browser version that fully supports the property.
Numbers followed by -webkit-, -moz-, or -o- specify the first version that worked with a prefix.
|4.0 -webkit-||15.0 -webkit-
|4.0 -webkit-||15.0 -webkit-
An animation lets an element gradually change from one style to another.
You can change as many CSS properties you want, as many times you want.
To use CSS3 animation, you must first specify some keyframes for the animation.
Keyframes hold what styles the element will have at certain times.
When you specify CSS styles inside the
rule, the animation will gradually change from the current style to the new style
at certain times.
To get an animation to work, you must bind the animation to an element.
The following example binds the "example" animation to the <div> element. The animation will lasts for 4 seconds, and it will gradually change the background-color of the <div> element from "red" to "yellow":
Note: If the
animation-duration property is not specified, the animation will have no effect, because
the default value is 0.
In the example above we have specified when the style will change by using the keywords "from" and "to" (which represents 0% (start) and 100% (complete)).
It is also possible to use percent. By using percent, you can add as many style changes as you like.
The following example will change the background-color of the <div> element when the animation is 25% complete, 50% complete, and again when the animation is 100% complete:
The following example will change both the background-color and the position of the <div> element when the animation is 25% complete, 50% complete, and again when the animation is 100% complete:
animation-delay property specifies a delay for the start of
The following example has a 2 seconds delay before starting the animation:
animation-iteration-count property specifies the number of times an animation should run.
The following example will run the animation 3 times before it stops:
The following example uses the value "infinite" to make the animation continue for ever:
animation-direction property is used to let an animation run in reverse direction or alternate cycles.
The following example will run the animation in reverse direction:
The following example uses the value "alternate" to make the animation first run forward, then backward, then forward:
animation-timing-function property specifies the speed curve of the
The animation-timing-function property can have the following values:
The following example shows the some of the different speed curves that can be used:
The example below uses six of the animation properties:
The same animation effect as above can be achieved by using the shorthand animation property:
The following table lists the @keyframes rule and all the animation properties:
|@keyframes||Specifies the animation code|
|animation||A shorthand property for setting all the animation properties (except animation-play-state and animation-fill-mode)|
|animation-delay||Specifies a delay for the start of an animation|
|animation-direction||Specifies whether an animation should play in reverse direction or alternate cycles|
|animation-duration||Specifies how many seconds or milliseconds an animation takes to complete one cycle|
|animation-fill-mode||Specifies a style for the element when the animation is not playing (when it is finished, or when it has a delay)|
|animation-iteration-count||Specifies the number of times an animation should be played|
|animation-name||Specifies the name of the @keyframes animation|
|animation-play-state||Specifies whether the animation is running or paused|
|animation-timing-function||Specifies the speed curve of the animation|