CSS Animations
Welcome, future front-end legends! If you’ve ever wanted your website to breathe, glow, or move like it’s alive, then CSS Animations are your magic wand.
At mkcoder.com, we believe coding is art. And with animations, you’re not just coding — you’re creating life on a screen.
What is CSS Animation?
In very simple words:
“CSS Animation is a way to make things move, fade, shake, zoom, or slide — all using just CSS (no JavaScript needed).”
Imagine a button that grows when you hover, or text that fades in like morning sunlight — that’s CSS animation.
How CSS Animation Works
There are two main parts to CSS animation:
@keyframes– This defines what happens (like move from left to right).animation property– This applies the animation to an element.
Let’s break it down.
🔧 Basic Example of CSS Animation
HTML (relevant part)
<div class="box"></div>
CSS (relevant part)
.box {
width: 100px;
height: 100px;
background-color: red;
animation: moveBox 2s infinite;
}
@keyframes moveBox {
from {
transform: translateX(0);
}
to {
transform: translateX(200px);
}
}
Example in action:
This will make the red box move 200px to the right every 2 seconds — forever!
Explanation (As Easy as a Poem)
@keyframes moveBox: This is like a short movie. You write its beginning and end.from / to: Beginning and end scenes.animation: moveBox 2s infinite;moveBoxis the name of the animation.2sis the duration (2 seconds).infinitemeans it keeps repeating forever.
Advanced CSS Animation Properties
Here are the most important ones:
| Property | What It Does |
|---|---|
animation-name |
Name of the keyframes you wrote |
animation-duration |
How long it should take |
animation-delay |
Wait before it starts |
animation-iteration-count |
How many times to repeat (e.g., infinite) |
animation-direction |
Normal, reverse, alternate |
animation-fill-mode |
Keeps final styles after animation ends |
animation-timing-function |
Easing (speed control) like ease, linear, ease-in-out |
Animation Timing Function (for Smoothness)
animation-timing-function: ease-in-out;
This makes the animation start slow, go fast in the middle, and end slowly — like a car taking a U-turn.
Other options:
linear– same speed alwaysease– start slow, end fastease-in– slow at beginningease-out– slow at end
Repeating Animation Example (infinite bounce)
CSS (relevant part)
@keyframes bounce {
0%, 100% {
transform: translateY(0);
}
50% {
transform: translateY(-30px);
}
}
.bounce {
animation: bounce 1s infinite
}
Example in action:
This makes the element jump up and down like a heartbeat.
Hover Animation
Wanna animate only when the user hovers?
CSS (relevant part)
.button {
transition: transform 0.3s ease;
}
.button:hover {
transform: scale(1.2);
}
Example in action:
transition is perfect
for hover effects.
Use animation for more control and keyframes.
📱 Real Life Use Cases for CSS Animations
- Buttons that grow or glow on hover
- Loading spinners
- Text fade-in or typewriter effect
- Slide-in menus
- Background color animations
- Image galleries with smooth transitions
More Beautiful Examples
Fade In Text
CSS (relevant part)
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
.text {
animation: fadeIn 2s ease-in;
}
Example in action:
This text fades in!
Glowing Button
CSS (relevant part)
@keyframes glow {
0% {
box-shadow: 0 0 5px #00f;
}
50% {
box-shadow: 0 0 20px #0ff;
}
100% {
box-shadow: 0 0 5px #00f;
}
}
.glow-btn {
animation: glow 1.5s infinite;
}
Example in action:
You’ll love this on dark mode buttons.
Combining Animation with JavaScript
Yes, Bhai! You can also trigger CSS animations using JS.
document.querySelector('.box').classList.add('animate');
Just define .animate
class with CSS
animation, and add it with JS whenever needed!
Build and Practice on mkcoder.com
Feeling pumped up? Go to 👉 mkcoder.com where you can learn step-by-step animations and play with live examples.
It’s your personal coding dojo, made for Indian students, freshers, and dreamers like you.
Conclusion: Animation is Art for Coders
CSS Animations don’t just move elements — they move emotions, attention, and energy into your design. They make your site alive, interactive, and joyful.
So next time you build something, add a little bounce, a soft glow, or a fade — because small animations create big experiences.
Need this in full HTML format or want Tailwind CSS animation examples?
Keep building, keep animating.