SVG paths are the most flexible way to draw shapes in SVG. A path consists of one or more commands stored in the d attribute. Each command moves the current point, draws straight lines, curves, or arcs, and together they define the final shape.
Almost every SVG shape (<rect>, <circle>, <ellipse>, <line>, <polyline>, and <polygon>) can be represented as a path, making paths the most general drawing primitive in SVG.
A single path may contain multiple subpaths. Each M (Move To) command starts a new subpath, which may be left open or closed using the Z command.
Every drawing command updates the current point (sometimes called the pen position). Relative commands (l, h, v, c, q, etc.) interpret their coordinates relative to the current point.
As a general rule, uppercase commands use absolute coordinates, while lowercase commands use coordinates relative to the current point.
Separators: Coordinate values may be separated by either commas or spaces. For example:
M 10,20
M 10 20
Both are equivalent.
Repeating Commands: Most commands accept multiple parameter sets. After the first command letter, additional parameter sets are interpreted as repeated uses of the same command. For example:
1
L 10,20 L 30,40
can be shortened to:
1
L 10,20 30,40
Move (M/m)
Command
Name
Parameters
Function
M / m
Move To
x, y
Moves the current point to a new position without drawing a line. If used after drawing commands, it starts a new subpath.
The first M command begins a new path. Any subsequent M commands begin new subpaths.
If additional coordinate pairs immediately follow an M or m command, they are treated as implicit L or l commands.
For example:
1
M 10,10 50,50 90,10
is equivalent to:
123
M 10,10
L 50,50
L 90,10
Line (L/l)
Command
Name
Parameters
Function
L / l
Line To
x, y
Draws a straight line to the target point.
1
<pathd="M 0,0 L 100,100"/>
Horizontal Line To (H/h)
Command
Name
Parameters
Function
H / h
Horizontal
x
Draws a horizontal line (Y coordinate remains unchanged).
1
<pathd="M 0,0 H 100"/>
Vertical Line To (V/v)
Command
Name
Parameters
Function
V / v
Vertical
y
Draws a vertical line (X coordinate remains unchanged).
1
<pathd="M 0,0 V 100"/>
Close Path (Z/z)
Command
Name
Parameters
Function
Z / z
ClosePath
None
Draws a straight line back to the starting point of the most recent M/m command, closing the shape.
1
<pathd="M 0,0 H 100 V 100 Z"/>
Cubic Bézier Curve
A cubic Bézier curve is defined by two control points. The curve begins at the current point and ends at (x, y). The control points determine the curve's direction and shape but generally do not lie on the curve itself.
Command
Name
Parameters
Function
C / c
Cubic Bézier
x1,y1 x2,y2 x,y
Draws a curve to x,y using the first control point (x1,y1) and the second control point (x2,y2).
S / s
Smooth Cubic
x2,y2 x,y
Continues the previous cubic Bézier curve smoothly. The first control point is automatically reflected from the previous C or S command.
1
<pathd="M 0,0 C 0,100 100,0 100,100"/>
123
<pathd="M 0,0 C 0,100 100,0 100,100 S 50,150 0,150"/><!-- Equals --><pathd="M 0,0 C 0,100 100,0 100,100 C 100,200 50,150 0,150"/>
Quadratic Bézier Curve
A quadratic Bézier curve uses one control point. Like cubic Bézier curves, the control point influences the shape of the curve but generally does not lie on the curve itself.
Command
Name
Parameters
Function
Q / q
Quadratic Bézier
x1,y1 x,y
Draws a curve to x,y using a single control point (x1,y1).
T / t
Smooth Quadratic
x,y
Continues the previous quadratic Bézier curve smoothly. The control point is automatically generated as the reflection of the previous one.
123
<pathd="M 0,0 Q 0,100 100,100"/><!-- Equals (see coversion formula) --><pathd="M 0,0 C 0,66.6667 33.3333,100 100,100 "/>
These formulas ensure the cubic has the same position and tangent at both ends, and because a quadratic Bézier is a special case of a cubic Bézier, the resulting cubic traces exactly the same curve.
Elliptical Arc
The A command draws a portion of an ellipse between the current point and the destination point.
Given the start point, end point, radii, and rotation, there are generally four possible arcs connecting the two points. The large-arc-flag selects the larger or smaller arc, while the sweep-flag selects the drawing direction.