CHAPTER 56
CSS Animations
Learn how @keyframes and animation properties create automatic CSS animations.
01. What is CSS Animations?
CSS animations can change styles over time without JavaScript.
@keyframes defines animation stages.
The animation property controls how the animation behaves.
02. Syntax
@keyframes name {
from {
property: value;
}
to {
property: value;
}
}
.element {
animation: name 2s infinite;
}
03. Example
CSS / HTML Example
AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>
<style>
@keyframes float {
0% {
transform: translateY(0);
}
50% {
transform: translateY(-20px);
}
100% {
transform: translateY(0);
}
}
.ball {
width: 100px;
height: 100px;
border-radius: 50%;
background: #2563eb;
animation: float 2s ease-in-out infinite;
}
</style>
</head>
<body>
<div class="ball"></div>
</body>
</html>
04. Important Points
✓
@keyframes defines animation stages.
✓
animation-duration controls the length.
✓
animation-iteration-count controls repetitions.
✓
animation-timing-function controls movement speed.
05. Common Mistakes
⚠
Using excessive animations.
⚠
Creating distracting infinite animations.
⚠
Ignoring users who prefer reduced motion.
⚠
Animating expensive properties unnecessarily.
06. Real World Use
Animations are used for loading indicators, hero effects, floating objects, notifications and interactive UI elements.
Ready to Practice? 🚀
Open the AIFA CSS Editor and practice this chapter live.
Try It Yourself →
Practice Exercise
Create a Floating Animation
Create a card that smoothly moves up and down using @keyframes.