Learn SVG
Short, practical guides. Most include code you can edit and see change right on the page.
Foundations
- What is SVG? A practical introduction
SVG is an XML-based format for 2D vector graphics. Learn how it works, the three ways to put it on a page, and when another format is the better choice.
- SVG vs PNG and JPEG: choosing an image format
When to use SVG, PNG or JPEG: vector versus raster, lossy versus lossless, transparency, and a simple decision guide with live examples.
- SVG vs Canvas: retained shapes or drawn pixels
Compare SVG and the HTML canvas: retained DOM shapes versus immediate pixel drawing, with code, trade-offs and clear advice on which to pick.
- SVG vs WebGL: when you need the GPU and when you do not
SVG and WebGL solve different problems. See what each does well, where WebGL is the right call for 3D and heavy graphics, and why most UI graphics stay SVG.
- The SVG viewBox explained, with preserveAspectRatio
How the viewBox attribute maps your drawing to the screen, how to shift and scale the coordinate system, and how preserveAspectRatio fits it into any box.
Drawing
- SVG paths: reading and writing the d attribute
Learn the SVG path commands (M, L, C, Q, A, Z), absolute versus relative coordinates, and how arc flags work, with live editable examples.
- SVG transforms: translate, rotate, scale and skew
Move, rotate, scale and skew SVG shapes with the transform attribute. Covers order of operations, pivot points, transform-box and when to use CSS instead.
- SVG masks and clipping paths: hide parts of a graphic
Use clipPath for hard-edged cut-outs and mask for soft fades. Includes luminance versus alpha, gradient masks, CSS clip-path and mask, and common pitfalls.
Motion and effects
- SVG filters: blur, shadow, color and distortion
Build SVG filter chains with feGaussianBlur, feDropShadow, feColorMatrix and feTurbulence, and learn filter regions, color space and when to avoid filters.
- SVG animation: SMIL, CSS and the Web Animations API
Compare SMIL, CSS and JavaScript animation for SVG, with working examples for draw-on strokes and motion paths, plus how to honor prefers-reduced-motion.
Building with SVG
- Responsive SVG: sizing, scaling and adapting to screens
Make SVG fit any container with viewBox and CSS, control cropping with preserveAspectRatio, reuse icons with symbol, and swap artwork by screen size.
- SVG with JavaScript: DOM, events and coordinates
Script inline SVG safely: create elements with createElementNS, convert pointer coordinates, drag shapes, measure paths, and control SMIL animation.
- SVG in React, Vue, Svelte and Astro
Use SVG in React, Vue, Svelte and Astro: inline markup, data-driven shapes, refs, safe HTML injection, and Astro's SVG components, with trade-offs for each.
- Interactive SVG infographics that work on touch and keyboard
Design SVG infographics with hover, focus and tap states, keyboard access, forgiving hit areas, tooltips and a detail panel, without relying on hover alone.
Quality and safety
- SVG accessibility
Give SVG graphics accessible names and descriptions, hide decoration, respect reduced motion, and avoid common labeling mistakes.
- SVG browser compatibility
What caniuse and MDN data show about SVG support across browsers, which old habits to drop, and how to test the cases that still bite.
- Optimizing SVG files
Shrink SVG with SVGO and server compression without breaking viewBox, titles or ids. Includes config examples and the trade-offs of each setting.
- SVG security
Why SVG can carry script, how img, inline, object and iframe differ, and how to handle uploads with sanitizing, separate origins, CSP and sandboxing.