HTML SVG <path>

Beginner
10 min read
Updated: Nov 2026
5 examples
Live preview

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

path.html
<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.

Attributes

Core <path> pieces and beginner commands:

NameDescriptionTry it
dPath data string (required to draw)Try it
M / LMove to / line to a pointTry it
H / VHorizontal / vertical lineTry it
Q / CQuadratic / cubic Bézier curveTry it
AElliptical arcTry it
ZClose path to the start pointTry it
pathLengthOptional length for dash / animation mathTry it

Global Attributes

The <path> tag also supports the Global Attributes in HTML (for example id, class, lang, title) when used in an HTML document.

Live Preview

Switch sample paths and stroke width. Same viewBox, different d values.

3

Start simple with M + L + Z, then add curves.

SVG

d="M 40 140 L 100 30 L 160 140 Z"

HTML Examples

Short, copy-ready snippets. Use Try It Yourself for a live editor.

Example 1 — Closed Triangle (M L Z)

Three lines, then close with Z.

HTML
<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>
Try It Yourself

How It Works

  1. M 40 140 moves to the first corner.
  2. L commands draw straight sides.
  3. Z closes back to the start.
  4. Fill paints the interior; stroke outlines the edges.

Example 2 — Open Path (Stroke Only)

No Z — a zig-zag line with fill="none".

HTML
<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>
Try It Yourself

How It Works

  1. Skip Z so the path stays open.
  2. fill="none" shows only the stroke.
  3. Round caps/joins soften corners.
  4. Similar to polyline, but ready to add curves later.

Example 3 — Quadratic Curve (Q)

Q needs one control point, then the end point.

HTML
<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>
Try It Yourself

How It Works

  1. M sets the start of the curve.
  2. Q cx cy x y uses control (cx, cy) and end (x, y).
  3. The control point pulls the bend (here, upward).
  4. Stroke-only keeps the demo clear.

Example 4 — Arc (A)

Elliptical arcs need radii, flags, and an end point.

HTML
<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>
Try It Yourself

How It Works

  1. A rx ry x-axis-rotation large-arc sweep x y draws the arc.
  2. rx / ry set ellipse radii (equal here = circular).
  3. Flags choose which of the possible arcs to take.
  4. End at (x, y) after the flags.

Example 5 — Cubic Curve (C)

C uses two control points for smoother S-curves.

HTML
<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>
Try It Yourself

How It Works

  1. C c1x c1y, c2x c2y, x y needs two controls + end.
  2. First control pulls near the start.
  3. Second control pulls near the end.
  4. 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.

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.

Key Takeaways

  • d holds the drawing commands.
  • Start with M, L, Z.
  • Curves: Q, C, and A.
  • Paint: fill and/or stroke must be visible.

One line: d commands + fill/stroke inside an <svg>.

Default CSS Settings

Conceptual SVG presentation defaults for paths:

defaults.css
/* 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

d is a string of commands and numbers that draws the path: move, line, curve, arc, and close.
Uppercase uses absolute coordinates. Lowercase uses offsets from the current point.
Add Z (or z) to draw a straight line back to the start. Closing helps fills look correct.
Common causes: fill none with no stroke, stroke-width 0, path outside the viewBox, or a broken d string.
Use path when you need curves, arcs, or mixed commands. Prefer line, polyline, polygon, or rect when those simpler elements are enough.
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

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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