CSS3 Animation is use to animate the HTML elements. An animation changes one style to another style of HTML element 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 number of times.
<html> <head> <style> div { width: 200px; height: 120px; background-color: red; font-size:20px; color:#fff; padding:15px; } div:hover{ animation-name: example; animation-duration: 4s; } @keyframes example { from {background-color: red;} to {background-color: yellow;} } </style> </head> <body> <div>Hover the mouse to change my color.</div> </body> </html>Same as Above:
@keyframes example { 0% {background-color: red;} 100% {background-color: yellow;} }
By using percent, you can add as many style changes as you like.
Example 2: Animation using percentage.
Output:Example 3: change both the background-color and the position.
Output:The animation-delay property specifies a delay for the start of an animation.
animation-delay: 2s;
The animation-iteration-count property specifies the number of times an animation should run.
animation-iteration-count: 3; animation-iteration-count: infinite;
The animation-direction property is used to run an animation in reverse direction or in alternate direction.
animation-direction: reverse; animation-direction: alternate;
The animation-timing-function property specifies the speed curve of the animation.
#div1 {animation-timing-function: linear;} #div2 {animation-timing-function: ease;} #div3 {animation-timing-function: ease-in;} #div4 {animation-timing-function: ease-out;} #div5 {animation-timing-function: ease-in-out;}