SVG Path Commands: All 20, Measured in Chrome
A path is twenty commands built from ten letters, and the letters do not take the same number
of coordinates. M, L and T take two; H and V take one; C takes six; S and Q take four;
A takes seven, two of which must be 0 or 1; Z takes none. That much is grammar. What
follows is grammar checked against a renderer: twenty-nine paths in a 200 × 200 box, each
one measured for bounding box, total length and ink pixels. The short curves are provably
short cuts: S reproduced an explicit C to the hundredth of a unit at 292.72 against 292.72,
T reproduced an explicit Q at 239.12, and four A commands drew a circle within 0.9 units of
<circle>. The failures are quieter than that: one illegal letter cut a
480-unit path down to 160 and the browser kept the first part without complaint.
Path data is the one part of an SVG with no fallback: a wrong fill is a wrong colour, but a wrong letter is a partially drawn shape nobody can explain from the file. So the useful question is not what each command does — the specification answers that — but what comes out, and what happens when one number is off.

The grammar: ten letters, six parameter counts
Every command takes a fixed count of numbers, and that count is the whole grammar. Moveto and lineto take a pair, horizontal and vertical lineto take one number each because the other coordinate does not change, and the curve commands take a pair plus their control points: two control points for C, one for S and Q, none for T. The arc is the odd one, because it packs radii, an axis rotation, two boolean flags and the end point into seven numbers.
There are twenty commands rather than ten because every letter exists in two cases, and the case is part of the name rather than a modifier. Z and z are the same close, but M and m are two different commands that happen to take the same input.
// The ten path letters and what each one consumes. A path is a stream of
// these; the case of the letter decides the coordinate frame, not the shape.
const PATH_SPEC = {
M: { numbers: 2, starts: true }, // moveto
L: { numbers: 2 }, // lineto
H: { numbers: 1 }, // horizontal lineto
V: { numbers: 1 }, // vertical lineto
C: { numbers: 6 }, // cubic bezier: two control points
S: { numbers: 4 }, // smooth cubic: one control point
Q: { numbers: 4 }, // quadratic bezier
T: { numbers: 2 }, // smooth quadratic
A: { numbers: 7, flags: 2 }, // elliptical arc: 2 of the 7 are flags
Z: { numbers: 0, closes: true }, // closepath
};
function commandTable() {
// twenty, because every letter exists in both cases
return Object.entries(PATH_SPEC).flatMap(([cmd, spec]) => [
{ cmd, relative: false, numbers: spec.numbers,
flags: spec.flags || 0, starts: !!spec.starts, closes: !!spec.closes },
{ cmd: cmd.toLowerCase(), relative: true, numbers: spec.numbers,
flags: spec.flags || 0, starts: !!spec.starts, closes: !!spec.closes },
]);
}
// parameter counts actually used, in the order the spec lists the commands
function parameterCounts() {
const seen = new Map();
for (const row of commandTable()) seen.set(row.numbers, (seen.get(row.numbers) || 0) + 1);
return [...seen.entries()].sort((a, b) => a[0] - b[0]);
}
Six parameter counts, then: 0, 1, 2, 4, 6 and 7. A parser needs nothing else to know where a
command ends and the next one begins — which is why numbers can be packed without separators, and
why M20 20L180 20 is valid. One letter can also serve a whole run: after an arc, the
next seven numbers are another arc with the same radii and flags, which is how
M20 100 A… A… consumed sixteen numbers, measured 377.04 long and
160 × 160 in the box. That is convenient for generators and merciless when a letter goes
missing, because the parser keeps consuming in groups of the previous command's size.
Upper and lower case: one geometry, two frames
The same shape written twice, once with absolute commands and once with relative ones, produces
identical output. M20 20 L180 20 L180 100 Z and
m20 20 l160 0 l0 80 z both report a bounding box of 160 × 80 at (20, 20), both
report a total length of 418.89, and both cover 13,284 pixels at 200 pixels wide. The
difference is not in the drawing; it is in what the digits mean.
That matters the moment you edit by hand. L180 20 moves to x = 180;
l180 20 moves 180 units right of wherever the pen is. And the first moveto is always
absolute even when it is written in lower case: m20 20 l160 0 starts at (20, 20),
measured as a 160 × 0 box at that origin, not at (40, 40).
Extra numbers after a moveto are an implicit lineto: M20 20 180 20 180 100 20 100 Z
is a move and three lines, 480 long against 480 with the letters
spelled out, and 13,284 pixels in both.
H and V are L with one number
Horizontal and vertical lineto exist to remove a repeated coordinate, and they do exactly that:
M20 20 H180 V100 H60 Z measures 160 × 80 like its lineto twin. But the length
is 449.44 against 418.89, and the difference is the last command. The three sides are 160, 80
and 120 units; the closing Z then draws a diagonal from (60, 100) back to (20, 20), which is
89.44 units. A closed orthogonal outline only works if the last point lines up with the first.
That is why Z is worth understanding as a command rather than as punctuation. It
draws a line back to the subpath start, and if the current point is not already there, the line is
a diagonal. In M20 20 h40 v40 z the closing side measures 56.57 units and the whole
path 136.57: two sides plus a hypotenuse, not a square.
S and T are reflections you can compute
The smooth commands do not invent a control point; they mirror the previous one. For S after a C, the first control point is the second control point of the C reflected through the current point. For T after a Q, it is the Q's control point reflected the same way. That is the entire rule, and it is checkable: the S path measured a bounding box of 160 × 99.41 and a length of 292.72; the explicit C with the mirrored control point (140, 140) measured 292.72, the same box, and 1,083 ink pixels in both. T and its explicit Q agreed at 239.12 and 876 pixels.
The corollary is the part people get wrong. If the command before S is anything other than a C or an S, there is no control point to mirror, so the specification says to use the current point — which makes the first control point coincide with the start. Measured, that path is 179.48 long, exactly equal to the explicit C with its first control at the start, bounding box 160 × 60. Nothing is undefined; it simply flattens the curve on one side.
So S and T are a compression scheme, not a different shape. Any S can be rewritten as a C and any T as a Q with no visual change; the reverse is only true when the preceding command is a curve. If you are generating path data, emitting C and Q everywhere costs bytes and never costs geometry.
A is the only command with flags
Seven numbers, two of them boolean: rx ry rotation large-arc sweep x y. The
rotation is in degrees and applies to the ellipse, not to the coordinate system. Everything
surprising about A comes from those two flags and from the fact that a radius is a request rather
than a promise.
Start with a half circle: from (20, 100) to (180, 100) with a radius of 80. Measured length
251.36, against π × 80 = 251.33. Then flip large-arc from 0 to 1 and measure
again: 251.36, the same box, the same pixels. With a chord that is exactly a
diameter there is only one circle through both points, so the flag has nothing to choose between.
Flipping sweep does something: the arc moves to the other side of the chord, and the
bounding box shifts from y = 20 to y = 100 — same size, mirror image.
A radius of zero is not an error. A0 80 measured a straight line of 160 units with
a bounding box 160 × 0, which is what the specification asks for: a degenerate radius means
draw a line. A radius that is too small for the endpoints is scaled up silently: asking for a
radius of 10 across a chord of 160 produced exactly the same arc as a radius of 80, 251.36 in both
cases. If your arc looks rounder than you specified, the browser is being helpful.
Rotating the ellipse is where the bounding box stops describing what you see. An 80 × 30
ellipse rotated 45 degrees measured a bounding box starting at (−21.67, −21.67) and
201.67 × 121.67 in size — larger than the 200 × 200 viewBox, which clips it. The path
is 366.24 long and paints 13,165 pixels, all of them inside the box; the rest of the geometry
exists and is invisible. getBBox() tells you about the art, not about the crop.
Four arcs make a circle, within 0.9 units
Four quarter arcs of radius 80 measured 502.73 in total length. A
<circle r="80"> on the same page reported 501.84, and 2πr is 502.65, so
the four-arc circle is accurate to about 0.2 percent. This is the one place in path data where a
hand-built approximation beats what people expect from approximations: an SVG arc is a true
elliptical arc, not a Bezier stand-in, so a chain of four of them is a circle rather than a
twenty-four-sided polygon pretending to be one.
The practical version: four arcs when you want the cardinal points as explicit nodes for animation or measurement, two when you only need the outline. Below four the shape starts to flatten visibly at the joins.
When a command is wrong, the path stops and the file does not
This is the finding with the most practical weight. Chrome does not reject a path with a bad command; it keeps every number before the error and drops the rest of the attribute. Five cases, all measured:
| d attribute | What survived, and how long it is |
|---|---|
M20 20 L180 20 X 100 100 L180 100 | the move and the first line, 160.00 units |
M20 20 L180 20 L100 180 L40 | the move and two lines, 338.89 units |
M20 100 L180 100 A80 80 0 0.5 1 180 20 | the move and one line, 160.00 units |
M20 100 A80 80 0 0.5 1 180 100 | nothing but the move, 0.00 units |
L180 20 L180 100 | nothing, because a path must start with M |
Two details make this worse than it looks. First, the message goes to the console and nowhere else: Error: <path> attribute d: Expected path command. Nothing appears on the page, nothing appears in a screenshot diff that only checks whether something was drawn. Second, the arc flags are the one place where a decimal is illegal — 0.5 instead of 0 produced a path length of zero with no visible hint that four numbers were the problem.
A scanner that follows the same rules catches all five before the file ships:
// Where the parser stops. Chrome keeps everything before the first bad token
// and drops the rest of the attribute, silently. This reproduces that rule.
function scanPath(d) {
const tokens = String(d).match(/[a-zA-Z]|-?(?:\d+\.\d*|\.\d+|\d+)(?:[eE][-+]?\d+)?/g) || [];
const isLetter = (t) => /^[a-zA-Z]$/.test(t);
let i = 0;
let kept = 0; // numbers the parser accepts
const letters = [];
const stop = (reason) => ({ ok: false, kept, letters, reason });
if (!tokens.length) return stop('empty attribute');
if (!isLetter(tokens[0]) || tokens[0].toUpperCase() !== 'M') {
return stop('a path must start with M or m');
}
while (i < tokens.length) {
const t = tokens[i];
if (!isLetter(t)) return stop(`expected a command, found ${t}`);
const spec = PATH_SPEC[t.toUpperCase()];
if (!spec) return stop(`unknown command ${t}`);
if (!letters.length && t.toUpperCase() !== 'M') return stop('a path must start with M or m');
i += 1;
const numbers = [];
while (i < tokens.length && !isLetter(tokens[i])) { numbers.push(+tokens[i]); i += 1; }
if (spec.numbers === 0) { letters.push(t); continue; }
const groups = Math.floor(numbers.length / spec.numbers);
for (let g = 0; g < groups; g += 1) {
const at = g * spec.numbers;
if (spec.flags) {
for (const k of [3, 4]) {
const v = numbers[at + k];
if (v !== 0 && v !== 1) return stop(`arc flag ${v} is not 0 or 1`);
}
}
kept += spec.numbers;
}
if (!groups) return stop(`${t} needs ${spec.numbers} numbers, found ${numbers.length}`);
if (numbers.length % spec.numbers) {
return stop(`${t} had ${numbers.length % spec.numbers} trailing number(s)`);
}
letters.push(t);
}
return { ok: true, kept, letters, reason: null };
}
Fill closes the shape, stroke does not
An open path and the same path with a Z differ by one side. Measured: the open version
M20 20 L180 20 L180 100 L20 100 is 400 units long and covers 13,202
pixels; adding Z makes it 480 and 13,284. The fill is identical — filling always
closes the shape implicitly — and the extra 80 units and 82 pixels are the stroke drawing the
fourth side.
So Z is a stroke instruction with a fill side effect. That is also why
stroke-linejoin has no visible effect on an open path: there is no join at the start
and end, only two caps. If a corner looks wrong, check for a missing Z before you touch the join
style; the geometry page on
stroke width and
scaling covers the other half of that problem.
Absolute or relative: 259 bytes against 253
Relative commands are usually described as smaller, and the measurement is more modest than the description. A twenty-four vertex star written with absolute linetos is 259 bytes; the same star written from deltas is 253, a saving of 6 bytes or 2.3 percent. A ten-point zigzag does better — 69 against 59, 14.5 percent — because its coordinates are large and its steps are small, so the deltas lose digits.
The rule behind both numbers: relative wins when the digits drop. At two decimal places the delta of two coordinates often has the same digit count as the coordinate itself, and the saving disappears. Below one decimal, the deltas start to pay. What never changes is the risk: relative coordinates accumulate, so a rounding error at every vertex compounds along the path — the precision page on how many decimals a path needs measured that drift at 0.51 pixels for one decimal against 0.04 for absolute.
// The same polyline written from deltas. Only M and L here on purpose: those
// are the two commands where the trade is measurable and the rewrite is safe.
const round = (v) => {
const r = Math.round(v * 10) / 10;
return Object.is(r, -0) ? 0 : r;
};
function toRelative(d) {
const tokens = String(d).match(/[a-zA-Z]|-?(?:\d+\.\d*|\.\d+|\d+)/g) || [];
const pts = [];
let cmd = null;
let cx = 0;
let cy = 0;
for (let i = 0; i < tokens.length; i += 1) {
const t = tokens[i];
if (/^[a-zA-Z]$/.test(t)) {
cmd = t;
if (t !== 'M' && t !== 'L' && t !== 'Z' && t !== 'z') {
throw new Error(`toRelative handles M, L and Z, not ${t}`);
}
continue;
}
if (cmd === 'M' || cmd === 'L') {
const x = +tokens[i];
const y = +tokens[i + 1];
i += 1;
pts.push([x, y]);
cx = x; cy = y;
}
}
if (!pts.length) return d;
let out = `m${round(pts[0][0])} ${round(pts[0][1])}`;
for (let i = 1; i < pts.length; i += 1) {
out += ` ${round(pts[i][0] - pts[i - 1][0])} ${round(pts[i][1] - pts[i - 1][1])}`;
}
return `${out}z`;
}
function pathBytes(d) {
return new TextEncoder().encode(d).length;
}
Convert only after the geometry is final. Rewriting a path to relative and then editing one point moves everything after it, which is the same failure as editing a sprite by hand.
Related SVG Workflows
Path data is where a drawing becomes arithmetic — the rest of the pipeline is mostly about boxes and bytes.
- Why Your SVG Does Not Show in a Browser — the other half of the diagnosis: 22 files that paint nothing, and which of them are parser problems.
- SVG viewBox vs width and height — the box a path is measured in, and why a viewBox-only file reports 300 by 138.
- How Many Decimals Does a Path Need? — 60 measured cells on rounding, and the drift that relative coordinates make worse.
- Stroke Width That Will Not Stay Put — why the same 4-pixel stroke measures 2 in one box and 16 in another.
- Unused SVG defs Cleanup — the definitions a path references, and which of them nothing uses.
- SVG Sprite Guide — what happens to path data when a drawing becomes a symbol.
- SVG Validator — run a file through the checks before the path reaches a reader.
Try These Free Online Tools
No download required — convert, compress & optimize SVGs right in your browser



