This skill guides creation of handcrafted SVG animations — from simple animated icons to complex multi-stage path animations. SVGs are a markup language for images; every element is a DOM node you can style, animate, and script.
SVG Fundamentals
Coordinate System
SVGs use a coordinate system defined by viewBox="minX minY width height". The viewBox is your canvas — all coordinates are relative to it, making SVGs resolution-independent.
Shape Primitives
The <path> Element — The Power Tool
The d attribute defines a path using commands. Uppercase = absolute, lowercase = relative.
Cubic Bézier (C): Two control points define the curve. The first control point sets the departure angle, the second sets the arrival angle.
Smooth Cubic (S): Reflects the previous control point automatically — perfect for chaining fluid S-curves.
Arc (A): rx ry x-rotation large-arc-flag sweep-flag x y
large-arc-flag: 0 = small arc, 1 = large arc (>180°)sweep-flag: 0 = counterclockwise, 1 = clockwise
Grouping and Transforms
Use <g> to group elements for collective transforms, styling, and animation targets.
Gradients, Masks, and Filters
CSS Animations on SVG
Many SVG attributes are valid CSS properties: fill, stroke, opacity, transform, stroke-dasharray, stroke-dashoffset, etc.
Basic CSS Animation
Stroke Drawing Animation (The Classic)
The most iconic SVG animation. Uses stroke-dasharray and stroke-dashoffset to make a path appear to draw itself.
How it works:
- Set
stroke-dasharrayto the path's total length (one giant dash + one giant gap) - Set
stroke-dashoffsetto the same length (shifts the dash off-screen) - Animate
stroke-dashoffsetto 0 (slides the dash into view)
Getting exact path length in JS:
Staggered Multi-Path Drawing
CSS d Property Animation
Modern browsers support animating the d attribute directly in CSS:
Requirement: Both paths must have the same number and types of commands for interpolation to work.
SMIL Animations (Native SVG)
SMIL animations are declared directly inside SVG markup. They work even when SVG is loaded as an <img> or CSS background-image — where CSS and JS can't reach.
<animate> — Animate Any Attribute
With keyframes:
<animateTransform> — Transform Animations
Types: translate, scale, rotate, skewX, skewY
<animateMotion> — Move Along a Path
rotate="auto" orients the element tangent to the path. rotate="auto-reverse" flips it 180°.
<set> — Discrete Value Changes
Timing and Synchronization
Trigger values:
begin="click"— on clickbegin="2s"— after 2 secondsbegin="other.end"— when another animation endsbegin="other.end + 1s"— 1s after another endsbegin="other.repeat(2)"— on 2nd repeat of another
Easing with calcMode and keySplines
calcMode options: linear (default), discrete, paced, spline
keySplines takes cubic-bezier control points (x1 y1 x2 y2) per interval. Common easings:
- Ease-in-out:
0.42 0 0.58 1 - Ease-out:
0 0 0.58 1 - Bounce-ish:
0.34 1.56 0.64 1
Shape Morphing with SMIL
Both shapes must have identical command structures (same number of points, same command types):
Animation Patterns & Recipes
Loading Spinner
Animated Checkmark
Morphing Hamburger to X
Gradient Animation (Color Shift)
Breathing / Pulsing Glow
Wave / Liquid Effect
Best Practices
-
Use
viewBox, never hardcodewidth/heightin the SVG — let the container size it. This keeps it resolution-independent. -
<defs>for reusable definitions — gradients, filters, masks, clipPaths, and reusable shapes belong in<defs>. -
Prefer SMIL for self-contained SVGs (icons, logos loaded via
<img>) — CSS/JS won't work there. Use CSS animations when the SVG is inlined and you want to coordinate with the rest of the page. -
Shape morphing requires matching commands — same number of path commands, same types, same order. If shapes differ, add invisible intermediate points to equalize.
-
stroke-linecap="round"makes line animations look polished. -
fill="freeze"in SMIL keeps the final animation state. Without it, the element snaps back. -
transform-origin: centerin CSS — SVG transforms default to the origin (0,0), not the element center. Always set this explicitly. -
Use
getTotalLength()in JS to get exact path lengths for stroke animations instead of guessing. -
Layer animations with
<g>groups — animate the group transform separately from individual element properties for complex choreography. -
Performance: SVG animations are GPU-composited when animating
transformandopacity. Animatingd,points, or layout attributes triggers repaints — use sparingly on complex SVGs. -
will-change: transformon animated SVG elements helps the browser optimize compositing. -
Accessibility: Add
role="img"and<title>/<desc>elements. Useprefers-reduced-motionmedia query to disable animations for users who request it:

