SVG Path

What You’ll Learn
The SVG <path> element is the most powerful shape in SVG. With a single d attribute, you can draw lines, curves, arcs, icons, and complex shapes.
You’ll learn the most important path commands and how to read them, then build two practical examples: a line + curve path and a closed shape.
⚡ Quick Reference — Path Commands
MMove to (x, y) without drawing
LLine to (x, y)
H / VStraight axis-aligned lines
CTwo control points + end point
QOne control point + end point
AElliptical arc segment
ZClose the shape
<svg>
<path d="M 10 10 L 50 10 L 50 50 Z" />
</svg>👀 Live Preview — Lines, Curves & Arcs
These previews help you visually connect commands to shapes.
Line + Cubic Bézier Curve
This matches the classic introduction: move to a point, draw a line, then draw a cubic Bézier curve using two control points.
<svg width="240" height="180" viewBox="0 0 240 180">
<path d="M 40 50 L 140 50 C 100 90 190 90 150 140"
fill="none" stroke="black" stroke-width="3" stroke-linecap="round" />
</svg>Closed Shape (Fill + Stroke)
Close the path using Z so fill works as expected. This is the foundation of icons and custom shapes.
<svg width="240" height="160" viewBox="0 0 240 160">
<path d="M 70 120 L 120 40 L 170 120 L 120 140 Z"
fill="#60a5fa" stroke="#1e3a8a" stroke-width="3" stroke-linejoin="round" />
</svg>🧠 How It Works
Start with M
M x y moves the pen to a point without drawing. Every path needs a starting point.
Draw with L / H / V
Use straight-line commands to build the skeleton: L for any line, H for horizontal, V for vertical.
Curve with C / Q
Bézier curves use control points to bend the line. C is cubic (two control points) and Q is quadratic (one control point).
Close with Z
Z closes the path by drawing a straight line back to the start. Closing is important for proper fills.
Any shape you can imagine
With a few commands, paths can replace many other SVG shapes and power icon sets, logos, and illustrations.
💡 Best Practices
Do
- Use
fill="none"and a visiblestrokewhen debugging shapes - Prefer a
viewBoxso paths scale responsively - Keep paths readable (spaces/line breaks) in tutorials
- Close shapes with
Zwhen you want a filled region - Use consistent stroke widths across an icon set
Don’t
- Mix absolute and relative commands without a reason (it gets confusing)
- Forget that SVG coordinates start in the top-left corner
- Assume a path will be visible without fill or stroke
- Copy-paste giant unformatted path data into tutorials
- Use many unnecessary decimals unless precision matters
❓ Frequently Asked Questions
d attribute is a compact set of commands and numbers that describes how to draw a path. It can create lines, curves, arcs, and closed shapes.Z (or z) command to close the shape by drawing a straight line back to the starting point. Closing helps fills render as expected.fill is set to none without a stroke, stroke-width is 0, the path is outside the viewBox, or the d value is malformed.fill/stroke like url(#id), and apply filters via filter="url(#id)", just like other SVG shapes.Fill Shapes with Patterns
Next, learn how to define SVG patterns and apply them to paths, rectangles, and more.
4 people found this page helpful
