CSS3 animations can replace animations created by Flash and JavaScript in existing web pages.
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.
Property | |||||
---|---|---|---|---|---|
@keyframes | 10.0 | 4.0 -webkit- | 16.0 5.0 -moz- |
4.0 -webkit- | 15.0 -webkit- 12.1 12.0 -o- |
animation | 10.0 | 4.0 -webkit- | 16.0 5.0 -moz- |
4.0 -webkit- | 15.0 -webkit- 12.1 12.0 -o- |
The @keyframes rule is where the animation is created.
Specify a CSS style inside the @keyframes rule and the animation will gradually change from the current style to the new style.
When an animation is created in the @keyframe rule, you must bind it to a selector, otherwise the animation will have no effect.
Bind the animation to a selector (element) by specifying at least these two properties:
Bind the "myfirst" animation to the <div> element. Animation duration: 5 seconds:
Note: If the duration part is not specified, the animation will have no effect, because the default value is 0.
An animation lets an element gradually change from one style to another.
You can change as many properties you want, as many times you want.
You can specify when the change will happen in percent, or you can use the keywords "from" and "to" (which represents 0% and 100%).
0% represents the start of the animation, 100% is when the animation is complete.
Change the background color when the animation is 25%, and 50%, and again when the animation is 100% complete:
Change the background color and the position when the animation is 25%, 50%, 75%, and again when the animation is 100% complete:
The example below uses seven of the animation properties:
The same animation effect as the example above (except the animation-play-state property). However, here we are using the shorthand animation property:
The following table lists the @keyframes rule and all the animation properties:
Property | Description | CSS |
---|---|---|
@keyframes | Specifies the animation | 3 |
animation | A shorthand property for setting all the animation properties, except the animation-play-state and the animation-fill-mode property | 3 |
animation-delay | Specifies when the animation will start | 3 |
animation-direction | Specifies whether or not the animation should play in reverse on alternate cycles | 3 |
animation-duration | Specifies how many seconds or milliseconds an animation takes to complete one cycle | 3 |
animation-fill-mode | Specifies what styles will apply for the element when the animation is not playing (when it is finished, or when it has a "delay") | 3 |
animation-iteration-count | Specifies the number of times an animation should be played | 3 |
animation-name | Specifies the name of the @keyframes animation | 3 |
animation-play-state | Specifies whether the animation is running or paused | 3 |
animation-timing-function | Specifies the speed curve of the animation | 3 |