Chapter 35: Animations

Animations

Animations are what make websites feel alive, premium, engaging, and memorable.

A transition (what we learned last time) is a very simple, automatic animation between two states (usually hover/focus/click).

A CSS animation (what we are learning today) gives you full control — you can:

  • animate over many steps (keyframes)
  • repeat forever or a specific number of times
  • control timing, delay, direction, fill mode
  • animate almost any property (not just hover)
  • run automatically when the page loads, when scrolled into view, or when a class is added

In 2026, good animations are subtle, purposeful, and performant — not the flashy 2010s bouncing everything.

Let’s learn it step by step like I’m sitting next to you with VS Code open.

1. Two Main Ways to Create Animations in CSS

Method When to use it Control level Complexity Performance
transition Simple state changes (hover, focus, class toggle) Low Very easy Excellent
@keyframes + animation Complex, multi-step, auto-running, looped animations High Medium Excellent (when using transform/opacity)

Today we focus on @keyframes + animation — the real animation system.

2. Basic Syntax – The Two Parts

Part 1: Define the animation with @keyframes

CSS

or more steps:

CSS

Part 2: Apply the animation to an element

CSS

Shorthand:

CSS

Most common values:

Property Common values Meaning
animation-name slideIn, bounce, fadeIn, etc. Which @keyframes to use
animation-duration 0.6s, 800ms, 1.2s How long one cycle takes
animation-timing-function ease, ease-in-out, linear, cubic-bezier(0.68, -0.55, 0.265, 1.55) Speed curve
animation-delay 0s, 0.3s, 500ms Wait before starting
animation-iteration-count 1, infinite, 3, 2.5 How many times to repeat
animation-direction normal, reverse, alternate, alternate-reverse Play forward/backward
animation-fill-mode none, forwards, backwards, both What styles to keep before/after animation
animation-play-state running, paused Pause on hover, etc.

3. Real, Playable Example – Multiple Animation Styles

index.html

HTML

style.css (only animation-focused)

CSS

What You Should Do Right Now

  1. Open with Live Server
  2. Scroll slowly → see fade-in on load
  3. Hover the slide card → watch it come from left
  4. Hover flip card → see 3D rotation
  5. Watch the red button pulse forever
  6. Try changing:
    • 1.2s to 2s in fadeIn → slower appearance
    • cubic-bezier(0.68, -0.55, 0.265, 1.55) → bouncy flip
    • infinite to 3 in bounce → stops after 3 times

Quick Animations Mastery Checklist (2026)

  • Use transform, opacity, filter for animations — best performance
  • Prefer cubic-bezier() over ease for natural feel
  • Keep durations 0.4s–1.2s — too long = annoying
  • Use animation-fill-mode: forwards when you want final state to stay
  • Add animation-play-state: paused on hover if needed
  • Test on mobile — avoid heavy 3D on low-end devices

How does the flip card feel when you hover? That smooth 3D rotation is why animations are everywhere in 2026 design.

Next possible lessons — tell me:

  • “10 beautiful micro-interactions using animations”
  • “page load animations & scroll-triggered effects”
  • “pure CSS loaders & spinners”
  • “animation vs transition — decision guide”
  • “performance tips for complex animations”

You’ve just learned how to give your websites motion & personality. Chai khatam? Fresh cup lao — let’s keep animating! 🚀 😄

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *