Chapter 10: SVG path

What makes <path> so powerful?

It has one main attribute: d (stands for “data” or “description”)

The d value is a mini programming language — a string of commands that tell the “pen” where to move and how to draw.

  • You pick up the pen → move without drawing → put pen down → draw lines or curves → close shape or not
  • All drawing happens in one single element (very efficient for the browser)

Basic syntax structure of d

Commands are letters (most have uppercase & lowercase versions) followed by numbers.

Uppercase = absolute coordinates Lowercase = relative to the previous point

Most common commands (we’ll learn them one by one):

Command Meaning Parameters Uppercase vs lowercase Closes path?
M / m MoveTo (jump, no draw) x y Absolute / relative No
L / l LineTo (straight line) x y (repeatable: x1 y1 x2 y2 …) Absolute / relative No
H / h Horizontal line x (only x changes) Absolute / relative No
V / v Vertical line y (only y changes) Absolute / relative No
Z / z ClosePath (no parameters) Same effect Yes
Q / q Quadratic Bézier curve cx cy x y Absolute / relative No
C / c Cubic Bézier curve cx1 cy1 cx2 cy2 x y Absolute / relative No
A / a Arc (elliptical arc) rx ry rotation large-arc sweep x y Absolute / relative No

Here are some excellent visual explanations of the most important path commands (especially Bézier curves and arcs):

The SVG `path` Syntax: An Illustrated Guide | CSS-Tricks
css-tricks.com
SVG Path Commands | Bezier Curves
nan.fyi
Building a Dynamic Tree Diagram with SVG and Vue.js | by Krutie Patel |  Medium
medium.com
Drawing an Arc with Canvas/SVG. To be more specific, an arc is a part… | by  Ovilia | Medium
medium.com

Example 1 – Simple rectangle using only path (compare to <rect>)

HTML
  • M 40 40 → start here (move without drawing)
  • L 260 40 → draw straight line to right
  • L 260 160 → down
  • L 40 160 → left
  • Z → close back to start

Same as <rect x=”40″ y=”40″ width=”220″ height=”120″> — but more flexible.

Example 2 – Heart shape (classic <path> example)

HTML
  • C = cubic Bézier → smooth curves with two control points each
  • Notice how symmetric it is — left and right sides mirror each other

Here is a visual breakdown of Bézier control points in curves:

Building a Dynamic Tree Diagram with SVG and Vue.js | by Krutie Patel |  Medium
medium.com
Building a Dynamic Tree Diagram with SVG and Vue.js | by Krutie Patel | Medium

Example 3 – Quadratic curve (simpler curve — only one control point)

HTML

Q = quadratic Bézier → one control point “pulls” the curve

Here is how quadratic curves look with control points:

automatic ref counting - How can I know the coordinates of the peak point  of an svg quadratic bezier arc? - Stack Overflow
stackoverflow.com
automatic ref counting – How can I know the coordinates of the peak point of an svg quadratic bezier arc? – Stack Overflow

Example 4 – Arc command (the hardest one — elliptical arcs)

HTML

A rx ry rotation large-arc-flag sweep-flag x y

  • rx, ry = horizontal & vertical radius
  • rotation = tilt in degrees
  • large-arc-flag (0 or 1) → choose small or large part of ellipse
  • sweep-flag (0 or 1) → clockwise or counterclockwise

Here are excellent arc command explanations:

Drawing an Arc with Canvas/SVG. To be more specific, an arc is a part… | by  Ovilia | Medium
medium.com
How to Draw an Arc with SVG - SVG Tutorial
svg-tutorial.com

Quick Cheat Sheet – Most used path patterns

Goal Typical starting commands
Simple closed shape M … L … L … Z
Smooth organic shape M … C … C … C … Z
Simple curve M … Q … or M … C …
Rounded button / pill M … H … A … H … A … Z
Icon with hole M … Z M … Z (even-odd fill-rule)
Dashed outline only fill=”none” stroke-dasharray=”8 4″

Common beginner mistakes

  • Forget to start with M or m → path invisible
  • Mix absolute & relative carelessly → shape jumps unexpectedly
  • Wrong number of parameters → path breaks
  • No stroke and no fill → invisible
  • Very long d strings → hard to read (tools like SVGOMG or Figma help)

Practice mini-challenges

  1. Draw a simple cloud using one <path> with several quadratic curves
  2. Make a speech bubble (rectangle + tail using arc or quadratic)
  3. Try to recreate a simple checkmark ✓ or arrow using only lines and Z

Paste your d string or full code here if you want feedback — I’ll review it like we’re pair-coding 😄

This is a huge topic — we’ve only scratched the surface! Which part feels most confusing: curves, arcs, relative vs absolute, or something else? Tell me and we’ll zoom in with more examples until it clicks perfectly! 🚀

You may also like...

Leave a Reply

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