CSS_Animation_and_Keyframes
CSS_Animation_and_Keyframes
detailing how an element's styles should change during the animation process. These keyframes
Syntax of @keyframes
--------------------
@keyframes animation-name {
from {
/* Initial styles */
to {
/* Final styles */
@keyframes animation-name {
0% {
/* Initial styles */
50% {
/* Midway styles */
100% {
/* Final styles */
How It Works
------------
1. Define the animation with @keyframes, specifying what happens at specific points (e.g., 0%,
50%, 100%).
-------------------------
@keyframes slide {
from {
transform: translateX(0);
to {
transform: translateX(100px);
.element {
}
Keyframes with Multiple Steps
-----------------------------
@keyframes bounce {
0% {
transform: translateY(0);
50% {
100% {
.element {
Properties of animation
-----------------------
When using @keyframes, you configure the animation with the following properties:
6. animation-direction: Whether the animation reverses on alternate cycles (e.g., normal, reverse,
alternate).
Complete Example
----------------
@keyframes colorChange {
0% {
background-color: red;
50% {
background-color: yellow;
100% {
background-color: green;
.element {
In this example:
Summary
-------
- Use @keyframes to define how styles change at different points of the animation.
- Combine with timing functions, delays, and iterations for complex animations.