Home SVG <path> HTML SVG <path> Definition
Definition and Usage The SVG <path> element draws any shape with one attribute: d (path data). Commands like M, L, Q, C, and Z move, draw lines, curve, and close.
Prefer simpler shapes when they fit — line , polyline , polygon — and use <path> for curves, arcs, and mixed outlines.
Baseline · Widely available. <path> is a core SVG shape across modern browsers since about July 2015.
Case matters. Uppercase commands (M, L) use absolute coordinates. Lowercase (m, l) use relative offsets from the current point.
Empty or broken d draws nothing. Start with M, check commas/spaces, and keep the path inside the viewBox.
Syntax
Syntax <svg width="200" height="160" viewBox="0 0 200 160"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Simple closed triangle path">
<path d="M 40 140 L 100 30 L 160 140 Z"
fill="#2563eb" stroke="#0f172a" stroke-width="3" />
</svg> Pattern: M start → draw commands → optional Z to close → style with fill/stroke.
Reference
Attributes Core <path> pieces and beginner commands:
Name Description Try it dPath data string (required to draw) Try itM / LMove to / line to a point Try itH / VHorizontal / vertical line Try itQ / CQuadratic / cubic Bézier curve Try itAElliptical arc Try itZClose path to the start point Try itpathLengthOptional length for dash / animation math Try it
Also supported
Global Attributes The <path> tag also supports the Global Attributes in HTML (for example id, class, lang, title) when used in an HTML document.
Try it
Live Preview Switch sample paths and stroke width. Same viewBox, different d values.
Code
HTML Examples Short, copy-ready snippets. Use Try It Yourself for a live editor.
1. Triangle 2. Open stroke 3. Quadratic 4. Arc 5. Cubic Example 1 — Closed Triangle (M L Z) Three lines, then close with Z.
<svg width="200" height="160" viewBox="0 0 200 160"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Filled triangle path">
<path d="M 40 140 L 100 30 L 160 140 Z"
fill="#2563eb" stroke="#0f172a" stroke-width="3" />
</svg> How It Works M 40 140 moves to the first corner.L commands draw straight sides.Z closes back to the start.Fill paints the interior ; stroke outlines the edges.Example 2 — Open Path (Stroke Only) No Z — a zig-zag line with fill="none".
<svg width="240" height="120" viewBox="0 0 240 120"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Open stroked zig-zag path">
<path d="M 20 80 L 70 30 L 120 80 L 170 30 L 220 80"
fill="none" stroke="#16a34a" stroke-width="4"
stroke-linecap="round" stroke-linejoin="round" />
</svg> How It Works Skip Z so the path stays open.fill="none" shows only the stroke.Round caps/joins soften corners.Similar to polyline , but ready to add curves later.Example 3 — Quadratic Curve (Q) Q needs one control point, then the end point.
<svg width="240" height="140" viewBox="0 0 240 140"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Quadratic bezier path">
<path d="M 20 110 Q 120 10 220 110"
fill="none" stroke="#7c3aed" stroke-width="5"
stroke-linecap="round" />
</svg> How It Works M sets the start of the curve.Q cx cy x y uses control (cx, cy) and end (x, y).The control point pulls the bend (here, upward).Stroke-only keeps the demo clear.Example 4 — Arc (A) Elliptical arcs need radii, flags, and an end point.
<svg width="220" height="140" viewBox="0 0 220 140"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Arc path between two points">
<path d="M 30 100 A 80 80 0 0 1 190 100"
fill="none" stroke="#ea580c" stroke-width="5"
stroke-linecap="round" />
</svg> How It Works A rx ry x-axis-rotation large-arc sweep x y draws the arc.rx / ry set ellipse radii (equal here = circular).Flags choose which of the possible arcs to take.End at (x, y) after the flags.Example 5 — Cubic Curve (C) C uses two control points for smoother S-curves.
<svg width="240" height="140" viewBox="0 0 240 140"
xmlns="http://www.w3.org/2000/svg"
role="img" aria-label="Cubic bezier path">
<path d="M 20 70 C 70 10, 170 130, 220 70"
fill="none" stroke="#2563eb" stroke-width="5"
stroke-linecap="round" />
</svg> How It Works C c1x c1y, c2x c2y, x y needs two controls + end.First control pulls near the start.Second control pulls near the end.Great for icons and smooth illustration outlines. Edge Cases & Pitfalls Most broken paths are paint settings, case mistakes, or bad d syntax.
paint Fill none needs a stroke Open curves often use fill="none". Without a stroke, you see nothing.
case Absolute vs relative Mixing up L and l shifts points. Stick to absolute commands while learning.
close Forgot Z on a filled shape Fills still try to close, but explicit Z makes the outline predictable.
choice Do not overuse path Straight segments alone? Prefer <line> / <polyline> / <polygon> for readability.
Compatibility
Browser Support The SVG <path> element is supported in every modern browser.
✓ Baseline · Widely available
SVG <path> Widely available since about July 2015. Chrome, Firefox, Safari, Edge, and Opera support path data commands. Internet Explorer 9+ supports basic SVG paths.
98% Global support (approx.)
Google Chrome All modern
Full support
Mozilla Firefox All modern
Full support
Apple Safari All modern
Full support
Microsoft Edge All modern
Full support
Opera All modern
Full support
Samsung Internet All modern
Full support
Internet Explorer 9+
Supported <path> Widely supported
Bottom line: Safe for production icons and illustrations. Keep d readable with spaces; start with absolute M/L/Q/C/Z while learning.
Remember
Key Takeaways One line: d commands + fill/stroke inside an <svg>.
UA style
Default CSS Settings Conceptual SVG presentation defaults for paths:
/* Conceptual SVG defaults */
path {
fill: black;
stroke: none;
stroke-width: 1;
} For open curves, set fill="none" and a visible stroke explicitly.
Frequently Asked Questions What is the SVG path d attribute? d is a string of commands and numbers that draws the path: move, line, curve, arc, and close.
Uppercase vs lowercase commands? Uppercase uses absolute coordinates. Lowercase uses offsets from the current point.
How do I close a path? Add Z (or z) to draw a straight line back to the start. Closing helps fills look correct.
Why is my path invisible? Common causes: fill none with no stroke, stroke-width 0, path outside the viewBox, or a broken d string.
When should I use path instead of line or polygon? Use path when you need curves, arcs, or mixed commands. Prefer line, polyline, polygon, or rect when those simpler elements are enough.
Can paths use gradients and filters? Yes. Use fill or stroke url(#id) and filter="url(#id)" like other SVG shapes.
Next: SVG Text Learn how to place and style text inside SVG.
SVG Text → About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful
Helpful Share Copy link Suggestion