Chapter 28: SVG Animation

SVG Animation means making any part of an SVG (shapes, paths, text, gradients, filters, transforms, strokes, opacity, colors, etc.) move, change, grow, fade, rotate, draw themselves, pulse, bounce, or morph over time — all inside the SVG code itself, without needing JavaScript in most cases.

The beauty of SVG animation is:

  • It’s vector → no matter how much you zoom or how big/small the screen, animation stays perfectly sharp
  • It’s lightweight → no heavy video or GIF files
  • It’s native → works directly in HTML, no extra libraries needed for basic stuff
  • It’s accessible & SEO-friendly → text & shapes remain readable
  • It’s widely supported in 2026 (all modern browsers)

There are three main ways people animate SVG in 2025–2026:

  1. SMIL (SVG’s own animation language) — old but still very powerful
  2. CSS Animations & Transitions — most popular & easiest for modern projects
  3. JavaScript (GSAP, Anime.js, Snap.svg, etc.) — when you need very complex control

We’ll cover all three, but focus mostly on SMIL + CSS because they are pure SVG/HTML and don’t need libraries.

1. SMIL – SVG’s Built-in Animation (The Classic Way)

SMIL (Synchronized Multimedia Integration Language) is written directly inside SVG tags.

Most common element: <animate>, <animateTransform>, <animateMotion>, <set>

Example 1 – Simple Color Change (Beginner SMIL)

HTML

→ Circle smoothly changes color orange → purple forever (3-second loop)

Example 2 – Rotate Forever (Most Famous SMIL Use)

XML

→ Square rotates 360° around its center forever

Key SMIL attributes everyone must know:

Attribute Meaning Common values
attributeName What to animate (fill, opacity, r, etc.) fill, opacity, transform, stroke-dashoffset
from / to Start and end value “red” to “blue”, 0 to 100
dur Duration of one cycle 2s, 5s, 10s
repeatCount How many times to repeat indefinite, 3, 5
begin When to start 0s, click, mouseover
fill (animation) What happens after animation ends freeze (stay at end), remove

2. CSS Animations & Transitions – The Modern & Most Popular Way (2026 Standard)

CSS is easier to read, works with hover/click, and combines perfectly with SVG.

Example 3 – Hover Scale + Rotate (CSS Only)

HTML

→ Hover → circle grows 30% bigger and tilts 15°

Example 4 – Drawing Animation (Very Famous – Stroke Dashoffset Trick)

HTML

→ Path “draws itself” from nothing to full line over 5 seconds

3. Combining SMIL + CSS + Transform (Real-World Power)

HTML

→ Circle pulses bigger/smaller forever (SMIL) → Hover → whole group spins (CSS)

4. Quick Reference Table – Which Method to Choose?

Goal Best Method Why?
Simple color/opacity change SMIL or CSS Both easy
Hover/click interaction CSS Native hover, :active, media queries
Path drawing / stroke animation CSS (dashoffset) Easiest & smoothest
Infinite rotation / pulsing SMIL or CSS Both good, SMIL more “SVG native”
Complex timeline / sequencing JavaScript (GSAP, Anime.js) Full control, chaining, easing
Legacy browser support SMIL Still works where CSS transform is weak

5. Teacher’s Final Tips 😄

  • Start with CSS for 80% of animations — easier to debug & maintain
  • Use stroke-dasharray + dashoffset for almost every “draw on scroll” or “loading” effect
  • SMIL has some deprecation warnings in Chrome → use CSS/JS for new projects if possible
  • Always test on mobile — heavy animations + filters can slow down
  • Common mistake: Forget transform-origin: center in CSS → rotation goes wrong
  • Pro trick: Combine SVG animation + <use> → reuse animated icons everywhere

Understood SVG Animation now? This is one of the most exciting parts of SVG — almost every modern icon library, loader, button hover, chart reveal, and interactive map uses these techniques.

Tell me what you want next:

  • Full “line drawing on scroll” example?
  • Animated gradient / fill change?
  • Morphing shape animation (SMIL <animate> on path d)?
  • Hover bounce + scale + shadow?
  • Or complete animated logo project?

Just say — we can animate anything together right now! 🚀

You may also like...

Leave a Reply

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