<path>
Core element
One element draws lines, curves, arcs, icons, and complex shapes.

SVG’s <path> is the most versatile shape element. This tutorial covers the d attribute, core commands (M, L, H, V, C, Q, A, Z), fill and stroke styling, five worked examples, and how <path> compares to simpler SVG shapes.
Core element
One element draws lines, curves, arcs, icons, and complex shapes.
Path data
A compact string of commands and coordinates that defines the shape.
Lines
Move the pen and draw straight segments in any direction.
Bézier curves
Cubic and quadratic curves bend paths with control points.
Arc & close
Elliptical arcs for rounded segments; Z closes the shape for fills.
Paint
Style open strokes or closed filled regions with presentation attributes.
SVG’s <path> is the Swiss Army knife of vector graphics. While <line>, <rect>, and <circle> cover common primitives, the path element can express anything they can — plus curves, arcs, and custom icons.
Everything lives in the d attribute: a mini language of single-letter commands followed by coordinates. Uppercase letters use absolute positions; lowercase letters use relative offsets from the current point.
Most SVG icon sets, logos, and illustrations are built from paths. Mastering d unlocks the full expressive power of SVG — from a simple arrow to a detailed map outline.
The entire shape is defined by the d string.
Mix straight segments, Bézier curves, and elliptical arcs.
Export paths from design tools or hand-write simple shapes.
Paths stay crisp at any size inside a responsive SVG.
In short: start with M, draw with line and curve commands, close with Z when you need a fill — that’s the foundation of SVG paths.
Basic form of the SVG path element:
<svg width="200" height="200" viewBox="0 0 200 200">
<path d="M 50 50 L 150 50 L 150 150 Z"
fill="#60a5fa" stroke="#1e3a8a" stroke-width="2" />
</svg> | Attribute | Type | Description |
|---|---|---|
d | Path data string | Commands and coordinates that define the shape. Required for any visible path. |
fill | Paint | Interior colour for closed paths. Defaults to black; use none for stroke-only. |
stroke | Paint | Outline colour. Required when fill="none". |
stroke-width | Length / number | Thickness of the outline in user units. |
stroke-linecap | Keyword | butt, round, or square end caps on open paths. |
stroke-linejoin | Keyword | miter, round, or bevel at corners. |
fill-rule | Keyword | nonzero or evenodd — how overlapping regions fill. |
| Command | Name | Parameters |
|---|---|---|
M / m | Move to | x y — pen up, move to point (start every sub-path) |
L / l | Line to | x y — straight line to point |
H / h | Horizontal line | x — horizontal line to x |
V / v | Vertical line | y — vertical line to y |
C / c | Cubic Bézier | x1 y1 x2 y2 x y — two control points + end point |
Q / q | Quadratic Bézier | x1 y1 x y — one control point + end point |
A / a | Elliptical arc | rx ry x-axis-rotation large-arc sweep x y |
Z / z | Close path | No parameters — line back to sub-path start |
<svg width="200" height="200" viewBox="0 0 200 200">
<path d="M 40 50 L 140 50 C 100 90 190 90 150 140"
fill="none" stroke="#0f172a" stroke-width="3" stroke-linecap="round" />
</svg> | Idea | Detail | Notes |
|---|---|---|
| Origin | (0, 0) is top-left | y grows downward |
| Uppercase | Absolute coords | Relative to SVG origin |
| Lowercase | Relative coords | Relative to current point |
| Visibility | Needs fill or stroke | fill="none" without stroke hides the path |
| Goal | Code |
|---|---|
| Move to point | M 10 10 |
| Line to point | L 50 50 |
| Horizontal line | H 100 |
| Vertical line | V 80 |
| Cubic curve | C 20 20 80 80 100 50 |
| Quadratic curve | Q 50 10 100 50 |
| Elliptical arc | A 30 30 0 0 1 100 50 |
| Close shape | Z |
| Stroke-only path | fill="none" stroke="#0f172a" stroke-width="2" |
| Filled closed path | fill="#60a5fa" stroke="#1e3a8a" stroke-width="2" |
<path> vs <line> vs <polyline> vs <polygon> vs <rect>Pick the simplest element that fits — use <path> when dedicated shapes are not enough.
any shapeLines, curves, arcs, icons — the most flexible option
one segmentStraight stroke between two points — simpler markup
open chainConnected straight segments without closing
closed polygonClosed straight-edged shapes from a point list
rectangleAxis-aligned boxes — not for curves or custom icons
<path>Reach for <path> when simpler SVG elements cannot express the shape you need.
Custom glyphs, brand marks, and UI icon sets.
Bézier curves for smooth connectors, waves, and illustrations.
Elliptical arcs for pie charts, gauges, and rounded UI elements.
Custom chart areas, map outlines, and annotation shapes.
For one straight segment, prefer <line> — clearer markup.
Key benefit: one d attribute can replace many other shape elements and power entire icon libraries.
Five starter snippets using <path>. Click View Output for a preview, or Try It Yourself to edit live.
Straight segments, cubic curves, and closed fills.
Move to a point, draw a line, then bend with a cubic Bézier using two control points (M L C).
<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> M 40 50 moves the pen. L 140 50 draws a horizontal line. C 100 90 190 90 150 140 curves through two control points to the end — the classic introduction to path curves.
Build a custom polygon-like shape and close it with Z so fill works as expected.
<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> Each L adds a corner. Z draws a straight line back to the start point, creating a closed region that can be filled.
Quadratic curves, arcs, and icon paths.
Use the Q command with one control point for a simpler curve than cubic Bézier.
<svg width="240" height="120" viewBox="0 0 240 120">
<path d="M 30 80 Q 120 10 210 80"
fill="none" stroke="#10b981" stroke-width="4" stroke-linecap="round" />
</svg> Q 120 10 210 80 pulls the curve toward control point (120, 10) before ending at (210, 80). Quadratic curves need fewer numbers than cubic — good for simple bends.
The A command draws an elliptical arc segment — useful for gauges, pie slices, and rounded connectors.
<svg width="240" height="120" viewBox="0 0 240 120">
<path d="M 40 80 A 80 50 0 0 1 200 80"
fill="none" stroke="#6d28d9" stroke-width="4" stroke-linecap="round" />
</svg> A rx ry x-axis-rotation large-arc sweep x y — here 80 50 sets ellipse radii, 0 0 1 picks the smaller arc sweeping clockwise, and the path ends at (200, 80).
A closed path built from cubic curves — the kind of shape exported from design tools for icon sets.
<svg width="240" height="200" viewBox="0 0 240 200">
<path d="M 120 170 C 120 170 40 110 40 75
C 40 45 70 35 95 55
C 110 68 120 68 120 68
C 120 68 130 68 145 55
C 170 35 200 45 200 75
C 200 110 120 170 120 170 Z"
fill="#ef4444" stroke="#991b1b" stroke-width="2" stroke-linejoin="round" />
</svg> Two mirrored cubic curves form the lobes; Z closes the bottom point. This pattern — export from Figma/Illustrator or hand-tune — powers most SVG icon libraries.
Real-world places where SVG paths show up every day.
Feather, Heroicons, and custom UI glyphs.
Example: hamburger menu icon from three path strokes.
Scalable company logos embedded inline.
Example: wordmark curve exported as a single path.
Area fills, map regions, and annotation overlays.
Example: filled area under a line chart.
Hand-drawn-style curves and organic shapes.
Example: wave divider between page sections.
Arc segments for dials and circular progress.
Example: semi-circle gauge with A command.
Teaching Bézier math, vector tools, and SVG internals.
Example: interactive control-point demos.
Pro Tip: export paths from design tools as optimized SVG, then simplify the d string for hand-edited tutorials.
Why paths are the backbone of SVG graphics.
Lines, curves, arcs, and complex icons in one element.
Stays sharp on retina screens without extra assets.
Fill, stroke, gradients, patterns, and filters all apply.
One path replaces many primitive elements in icon sets.
Animate stroke-dashoffset, morph d, or tween control points.
Pro Tip: for stroke-based icons, stroke="currentColor" lets paths inherit the parent text colour for theming.
Follow these practices for clean, maintainable SVG paths.
Every sub-path needs a move command before drawing begins.
Use Z when you want a reliable fill region.
Define geometry once, then size the SVG with CSS.
Set fill="none" and a visible stroke while learning path data.
Use <rect> or <line> when they fit — clearer markup.
Pro Tip: add spaces or line breaks in the d string when teaching — readability matters more than byte count in tutorials.
Avoid these mistakes when your path refuses to show up.
A path with fill="none" and no stroke is invisible.
→ Set at least one of fill or stroke.
Missing numbers or wrong command order breaks rendering.
→ Validate with a viewer or SVG optimizer tool.
Path coordinates outside the canvas get clipped.
→ Adjust coordinates or expand the viewBox.
Open paths may fill unexpectedly or not at all.
→ Add Z at the end when you need a filled region.
A rectangle written as path data is harder to read than <rect>.
→ Pick the dedicated element when it covers your needs.
Pro Tip: if a path vanishes, check fill/stroke, then paste the d value into an SVG editor to spot malformed commands.
<path> Is DrawnThe browser reads the d string as a sequence of commands (M, L, C, etc.) and their numeric parameters.
M x y lifts the pen to the start. Line commands connect straight segments to build the skeleton.
Bézier commands bend the path through control points. The arc command adds elliptical segments for rounded shapes.
Z closes the sub-path. Then fill and stroke paint the interior and outline.
The browser renders the path as live vector geometry — sharp at every zoom level.
d attribute is the most powerful shape command in SVG.Z closes the current sub-path back to its start.<polyline> or <line>.viewBox when the graphic must scale responsively.Quick Takeaway: start with M, draw with commands, close with Z for fills — then style with fill and stroke.
The SVG <path> element is supported in all modern browsers — and has been for many years — as part of SVG 1.1 path data.
Use
Bottom line: Safe for production sites. Prefer inline SVG or cached .svg assets; no polyfill is required for current browsers.
SVG <path> is the most flexible shape on the web: one d attribute draws lines, curves, arcs, icons, and complex closed regions.
Practice the five examples above, then continue to SVG Text to add labels and typography to your graphics.
Start with simple M L Z shapes, then add curves and arcs as you grow comfortable reading path data.
MZ when you need fillsfill="none" and a visible stroke while debuggingviewBox for responsive icons<rect> or <line> would be clearer<path>Draw any shape the SVG way.
Path data string
APIM, L, H, V
GeometryC & Q Bézier
CurvesA & Z
ShapePaint the path
StyleThe SVG <path> element’s d attribute is the most powerful shape command in SVG — one attribute can draw lines, curves, arcs, icons, and complex closed shapes that no other basic element can express. You can animate stroke-dashoffset on paths to create draw-on effects — a popular technique for loaders and signature animations.
Learn how to add labels, titles, and typography inside your SVG graphics.
8 people found this page helpful