To create animations in CSS3, you will have to learn about the @keyframes rule.
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.
Internet Explorer 10, Firefox, and Opera supports the @keyframes rule and animation property.
Chrome and Safari requires the prefix -webkit-.
Note: Internet Explorer 9, and earlier versions, does not support the @keyframe rule or animation property.
When the animation is created in the @keyframe, bind it to a selector, otherwise the animation will have no effect.
Bind the animation to a selector by specifying at least these two CSS3 animation properties:
Binding the "myfirst" animation to a div element, duration: 5 seconds:
Note: You must define the name and the duration of the animation. If duration is omitted, the animation will not run, because the default value is 0.
An animation is an effect that lets an element gradually change from one style to another.
You can change as many styles you want, as many times you want.
Specify when the change will happen in percent, or the keywords "from" and "to", which is the same as 0% and 100%.
0% is the beginning of the animation, 100% is when the animation is complete.
For best browser support, you should always define both the 0% and the 100% selectors.
Change the background color when the animation is 25%, 50%, and again when the animation is 100% complete:
Change the background color and position:
The following table lists the @keyframes rule and all the animation properties:
|@keyframes||Specifies the animation||3|
|animation||A shorthand property for all the the animation properties, except the animation-play-state property||3|
|animation-name||Specifies the name of the @keyframes animation||3|
|animation-duration||Specifies how many seconds or milliseconds an animation takes to complete one cycle. Default 0||3|
|animation-timing-function||Describes how the animation will progress over one cycle of its duration. Default "ease"||3|
|animation-delay||Specifies when the animation will start. Default 0||3|
|animation-iteration-count||Specifies the number of times an animation is played. Default 1||3|
|animation-direction||Specifies whether or not the animation should play in reverse on alternate cycles. Default "normal"||3|
|animation-play-state||Specifies whether the animation is running or paused. Default "running"||3|
The two examples below sets all the animation properties:
Run an animation called myfirst, with all the animation properties set:
The same animation as above, using the shorthand animation property:
The perfect solution for professionals who need to balance work, family, and career building.
More than 10 000 certificates already issued!
The HTML Certificate documents your knowledge of HTML.
The HTML5 Certificate documents your knowledge of advanced HTML5.
The CSS Certificate documents your knowledge of advanced CSS.
The jQuery Certificate documents your knowledge of jQuery.
The XML Certificate documents your knowledge of XML, XML DOM and XSLT.
The ASP Certificate documents your knowledge of ASP, SQL, and ADO.
The PHP Certificate documents your knowledge of PHP and SQL (MySQL).
Your message has been sent to W3Schools.