SVG Tutorial

1. What Exactly Is SVG? (The Big Picture First)

SVG stands for Scalable Vector Graphics. It’s a way to create 2D images using code (XML language, like super-simple HTML) instead of pixels.

  • Key Superpower: You can zoom in forever — no blur, no pixelation! Perfect for logos, icons, maps, charts, animations on websites.
  • Analogy: Think biryani photo (raster = PNG/JPG) vs. biryani recipe (vector = SVG).
    • Photo: Fixed pixels → zoom = blurry mess.
    • Recipe: “Take 1kg rice + spices + draw circle for plate” → scale to any size, still perfect.

Raster (PNG/JPG/GIF) vs Vector (SVG) comparison:

Vector vs Raster: Why Your Image Looks Blurry - eufymake US
eufymake.com
SVG vs Raster Images: Complete Format Comparison Guide
svgmaker.io

See? Zoom raster → squares. Zoom SVG → smooth forever!

SVG is:

  • Text file (.svg) → open in Notepad, edit like HTML
  • W3C standard (same people who made HTML/CSS)
  • Works everywhere: browsers, Figma, Illustrator, React, etc.
  • Lightweight + searchable (Google can read text inside SVG!)

2. Why Learn SVG in 2026? (Real-World Reasons)

  • Responsive websites: Icons stay sharp on 4K phones & big monitors
  • Small file size for simple shapes (better than 10 PNGs)
  • Animatable with CSS/JS (spin icons, morph shapes)
  • Interactive: Click parts, change color on hover
  • Great for games too: UI elements, HUDs, particle effects (remember our game images talk?)

3. How to Use SVG: 4 Main Ways (Pick Your Style)

Way Code Example When to Use Pros Cons
Inline SVG <svg>…</svg> directly in HTML Need CSS/JS control, animations Full power, style with CSS Code bloats HTML
<img> tag <img src=”icon.svg” alt=”logo”> Simple static icons Easy, cacheable No internal styling/animation
CSS background background: url(‘icon.svg’) Background patterns Repeatable Limited interaction
<object> <object data=”icon.svg” type=”image/svg+xml”> Fallback support needed Works old browsers Harder to style

Teacher favorite: Start with inline — most fun & powerful!

4. The SVG Canvas: Tag Basics

Every SVG starts with <svg> — like <body> for graphics.

HTML
  • width/height: Display size on page (pixels or %)
  • viewBox=”minX minY width height”: Your “coordinate paper” (most important!). Example: viewBox=”0 0 100 100″ → think 100×100 grid, scales perfectly.

Analogy: viewBox = biryani plate size. width/height = how big you serve it on table. Same recipe, different plate = no distortion!

5. Basic Shapes: Draw Like Kindergarten!

SVG has ready-made shapes. Let’s code them!

HTML SVG course lesson | Uxcel
app.uxcel.com
HTML SVG course lesson | Uxcel

Circle (Yellow Ball)

HTML
  • cx/cy = center x/y
  • r = radius
  • fill = inside color
  • stroke = border, stroke-width = thickness

Rectangle (Biryani Plate)

HTML
  • x/y = top-left corner
  • rx/ry = rounded corners (super useful!)

Line & Polyline

HTML

Polygon (Star/Arrow)

HTML

Path (The Boss Shape — Most Powerful) <path> draws anything with d=”commands”.

Simple smiley face path:

HTML
SVG essentials. Basic shapes and path - DEV Community
dev.to
Practical SVG by Chris Coyier
practical-svg.chriscoyier.net

Common path commands:

  • M = MoveTo (start point)
  • L = LineTo
  • Q = Quadratic Bézier curve
  • C = Cubic Bézier (smooth curves)
  • A = Arc
  • Z = close path

6. Styling SVG: CSS Power

Inline SVG = style with CSS like HTML!

CSS

Or inline:

HTML

Gradients too:

HTML

7. Quick Practice: Make a Simple Icon Right Now!

Copy this into a .html file and open in browser:

HTML

Tada! Your own scalable chai icon. Zoom browser — perfect every time!

8. Next Level Teasers (When You’re Ready)

  • Animations:<animate> or CSS @keyframes
  • Filters: Blur, shadow, glow
  • JavaScript: Click → change color
  • Tools: Figma → export SVG, Inkscape (free), SVGOMG (optimize code)

9. Your Homework Challenge!

Make an SVG:

  1. Simple flag of India (rect + circle + paths for chakra)
  2. Or your initials in cool shapes Paste code in reply — I’ll review like teacher! 😄

SVG is like “HTML for pictures” — once you get shapes + viewBox, sky’s limit. Questions? “Sir, path d attribute samajh nahi aa raha”? Hit me! Next: “SVG Animation” or back to games?

Class dismissed… now go code some vectors! 🎨🚀