SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10
Try this code live
Lesson 29 of 35

CSS Transitions & Animations — No JavaScript Needed

4 min read · Free · No login needed

A button that instantly snaps from grey to green feels dead. A button that smoothly fades to green over a quarter of a second feels alive. That smoothness is a transition. And a ball that bounces on its own, or a card that slides into view when the page loads, is an animation. Both are pure CSS — no JavaScript needed at all.

Diagram — see how it fits together
Diagram: CSS Transitions and Animations

The difference is simple: a transition is a smooth change between two states, like normal and hover. An animation is a set of steps that plays on its own, like a bounce or a spin, and it can repeat forever.

Transitions — smooth changes on hover

A transition needs two things: a starting style, a different style on :hover, and the transition property telling the browser to glide between them instead of jumping. You say which property changes and how long the glide takes — transition: background-color 0.3s means "when the background colour changes, take 0.3 seconds to get there".

Syntax — a button that grows on hover

.btn {
  background-color: #04aa6d;
  color: white;
  padding: 12px 24px;
  transition: background-color 0.3s, transform 0.3s;
}
.btn:hover {
  background-color: #038857;
  transform: scale(1.1);
}

When the mouse hovers over the button, its colour darkens and it grows by 10% — both changes glide smoothly over 0.3 seconds. When the mouse leaves, the button glides back. You can list several properties in one transition, separated by commas.

Animations — @keyframes

An animation is a small movie written in CSS. The @keyframes rule describes the steps: what the element looks like at the start (from or 0%), in the middle, and at the end (to or 100%). Then the element is told which animation to play, how long it takes, and how many times to repeat it.

@keyframes bounce {
  0% { transform: translateY(0); }
  50% { transform: translateY(-40px); }
  100% { transform: translateY(0); }
}
.ball {
  animation: bounce 1s infinite;
}

The ball rises 40 pixels at the halfway point and lands again at the end, and infinite makes it bounce forever. Change infinite to a number like 3 and it bounces exactly three times.

Note: transform (scale, translate, rotate) and opacity are the smoothest properties to animate, because the browser can move them without recalculating the whole page layout. Animating width, height, or margin works too, but it can feel jerky on slower phones.
Tip: Keep animations short and gentle — 0.3 seconds for a hover, 1 second for a bounce. Long, flashy animations annoy visitors and make a page feel slow. And respect people who prefer less movement: a @media (prefers-reduced-motion: reduce) rule can turn your animations off for them.

Common mistakes

  • Writing the :hover style but forgetting the transition property — the change happens instantly instead of gliding.
  • Putting transition only on the :hover rule — it must be on the normal rule, so the glide works both when the mouse arrives and when it leaves.
  • Forgetting the @keyframes name must match the animation name — a spelling difference means nothing moves.
  • Animating width or margin for a simple hover effect — transform: scale() does the same job far more smoothly.
  • Making animations too long or repeating everything forever — movement should guide the eye, not distract from the content.

Remember

  • A transition glides between two states, like normal and :hover.
  • transition: background-color 0.3s says which property changes and how long it takes.
  • Put transition on the normal rule, not on :hover.
  • @keyframes describes the steps; animation plays them, for a time and a number of repeats.
  • Animate transform and opacity for the smoothest movement.

Example explained

  • .btn { transition: background-color 0.3s, transform 0.3s; } — the button is told to glide for 0.3 seconds whenever its colour or size changes.
  • .btn:hover { transform: scale(1.1); } — on hover the button grows 10% bigger and turns a darker green, smoothly instead of snapping.
  • @keyframes bounce — the three steps of the ball's jump: on the ground at 0%, 40 pixels up at 50%, and back on the ground at 100%.
  • .ball { animation: bounce 1s infinite; } — the ball plays the bounce animation, one second per bounce, forever.
  • .card { animation: slide-in 0.8s; } — the welcome card slides in from the left once when the page loads, using translateX from -100px to 0.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Transitions and Animations</title>
<style>
body { font-family: Arial, sans-serif; margin: 0; padding: 20px; text-align: center; background-color: #f2f2f2; }
.card {
  background-color: white;
  max-width: 500px;
  margin: 0 auto 30px auto;
  padding: 25px;
  border-radius: 10px;
  animation: slide-in 0.8s;
}
@keyframes slide-in {
  from { transform: translateX(-100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.btn {
  background-color: #04aa6d;
  color: white;
  padding: 12px 24px;
  border: none;
  border-radius: 6px;
  font-size: 18px;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.3s;
}
.btn:hover { background-color: #038857; transform: scale(1.1); }
.ball {
  width: 60px;
  height: 60px;
  background-color: #ff5722;
  border-radius: 50%;
  margin: 40px auto;
  animation: bounce 1s infinite;
}
@keyframes bounce {
  0% { transform: translateY(0); }
  50% { transform: translateY(-40px); }
  100% { transform: translateY(0); }
}
</style>
</head>
<body>

<div class="card">
<h1>Welcome to CSS Animations</h1>
<p>This card slid in from the left when the page loaded.</p>
<button class="btn">Hover Over Me</button>
</div>

<div class="ball"></div>
<p>The ball bounces forever — pure CSS, no JavaScript.</p>

</body>
</html>

Output

Output — how it looks in the browser
Output of CSS Transitions & Animations — No JavaScript Needed

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What is the difference between a transition and an animation?

A transition glides between two states, like normal and hover. An animation plays keyframe steps on its own, with no trigger needed.

2. Where should the transition property go?

On the normal rule, not on :hover, so the glide works both when the mouse arrives and when it leaves.

3. What makes the smoothest animations?

Animating transform and opacity gives the smoothest movement.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Core Python Programming – 3 Month Complete Course
₹700
View
Full Stack PHP Development Course 2026
₹3,000
View
Ethical Hacking & Cyber Security Workshop
View
Browse all courses
CSS — Lessons
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →