The CSS3 animation property allows us to use multiple CSS Style properties at a specific interval. We use keyframes for applying animation on an HTML element.
How to use animation property on your web page?
Animation property gives an attractive look to your website. We can use multiple animations at a time on an HTML element.
These values allow us to add different animation effects on our web page.
<style>
.tdb-block{
padding:5px 10px;
width:100px;
height:50px;
background-color:black;
animation:animation-name 1s;
}
/* animation @keyframe rule */
@keyframes animation-name {
from {margin-left: 0px}
to {margin-left: 250px;}
}
</style>
<div class="tdb-block">tdb-block</div>
First, we have to specify some keyframes for the animations. Keyframes allow holding CSS styles for a specific duration.
<style>
/* animation @keyframe rule */
@keyframes example {
from {property: value}
to {property: value;}
}
</style>
We can also specify multiple CSS3 properties during the animation
<style>
/* multiple animation effects */
@keyframes animation-name {
0% {margin-left: 0px;}
20% {margin-left: 100px;}
30% {margin-left: 50px;}
50% {margin-left: 200px;}
80% {margin-left: 100px;}
100% {margin-left: 250px;}
}
</style>
<head>
<style>
.tdb-block{
padding:5px 10px;
width:100px;
height:50px;
background-color:black;
animation:animation-name 1s;
}
/* animation @keyframe rule */
@keyframes animation-name {
0% {margin-left: 0px;}
20% {margin-left: 100px;}
30% {margin-left: 50px;}
50% {margin-left: 200px;}
80% {margin-left: 100px;}
100% {margin-left: 250px;}
}
</style>
</head>
<body>
<div class="tdb-block">tdb-block</div>
</body>
We can also use other values used in animation.
<style>
/* animation delay*/
.tdb-animation{
animation-name: tdb-animation;
animation-duration: 4s;
animation-delay: 5s;
}
/*now the animation will start after 5 seconds */
</style>
<style>
/*animation-iteration-count*/
.tdb-animation{
animation-iteration-count: 5 /*or infinite*/;
}
/*the animation will run for 5 times */
</style>
SYNTAX
animation-timing-function: ease-in | ease-out | linear | ease | cubic-bezier(n,n,n,n) | step-start | step-end | ease-in-out | steps(int,start | end) | initial | inherit;
<style>
/*animation timing function*/
.tdb-animation{
animation-timing-function: linear;
}
</style>
<!DOCTYPE html>
<html>
<head>
<style>
.tdb-block
{
padding:5px 10px;
width:100px;
height:50px;
background-color:black;
animation:animation-name 1s;
animation-delay: 1s;
animation-iteration-count: 5;
animation-timing-function: linear;
}
/* animation @keyframe rule */
@keyframes animation-name
{
0% {
margin-left: 0px;
}
20% {
margin-left: 100px;
}
30% {
margin-left: 50px;
}
50% {
margin-left: 200px;
}
80% {
margin-left: 100px;
}
100% {
margin-left: 250px;
}
}
</style>
</head>
<body>
<div class="tdb-block">tdb-block</div>
</body>
<html>
Syntax
animation-direction: normal | reverse | alternate | alternate-reverse;
<style>
/* animation delay*/
.tdb-animation{
animation-name: tdb-animation;
animation-duration: 4s;
animation-direction: normal | reverse | alternate
| alternate-reverse;
}
</style>
Syntax
animation-fill-mode: none | forwards | backwards | both | initial | inherit;
<style>
/*animation-iteration-count*/
.tdb-animation{
animation-iteration-count: 5;
animation-fill-mode: backward;
}
</style>
SYNTAX
animation: animation-name duration timing-function delay iteration-count direction fill-mode play-state;
<style>
/*animation timing function*/
.tdb-animation{
animation: tdb-animation 10s linear 5s 3 forward;
}
</style>
<!DOCTYPE html>
<html>
<head>
<style>
.tdb-block
{
padding:5px 10px;
width:100px;
height:50px;
background-color:black;
animation:animation-name 1s;
animation-direction: normal;
animation-fill-mode: backward;
animation-delay: 1s;
animation-iteration-count: 5;
animation-timing-function: linear;
animation-direction: normal;
animation-fill-mode: backward;
}
.animation{
animation: tdb-animation 5s linear;
padding:5px 10px;
width:100px;
height:50px;
background-color:orange;
}
@keyframes tdb-animation
{
0% {
margin-left: 0px;}
100% {
margin-left: 250px;}
}
@keyframes animation-name
{
0% {
margin-left: 0px;}
100% {
margin-left: 250px;}
}
</style>
</head>
<body>
<div class="tdb-block">tdb-block</div></br>
<div class="animation">tdb-block</div>
</body>
<html>