opyeb SVGForge

Guides · Path data

The SVG path d attribute: every command, absolute versus relative, and arc flags

Updated 28 Nov 2026 · 10 min read

The d attribute is a tiny drawing language. It is a sequence of commands, each a letter followed by numbers: M moves the pen, L draws a line, C and Q draw curves, A draws an elliptical arc and Z closes the shape. Upper-case letters are absolute coordinates in the user space, lower-case letters are relative to the current point. Both forms produce the same outline.

A parser reads the letter, then consumes as many numbers as that command needs, repeating the command for every extra group. M 10 10 20 20 30 30 is a move followed by two implicit line-tos. This implicit repetition is why a path can be shorter than it looks and why hand-editing is error prone: one missing number shifts every following coordinate.

The commands in one table

CommandArgumentsMeaning
M / mx yMove to a point, starting a new subpath
L / lx yStraight line to a point
H / hxHorizontal line
V / vyVertical line
C / cx1 y1 x2 y2 x yCubic Bézier with two control points
S / sx2 y2 x yCubic that reflects the previous control point
Q / qx1 y1 x yQuadratic Bézier with one control point
T / tx yQuadratic that reflects the previous control point
A / arx ry rot large sweep x yElliptical arc to a point
Z / z—Close the subpath back to its start

Absolute or relative

Relative commands encode the difference from the current point, so they tend to be short when points are close together and long when the drawing jumps across the canvas. Absolute commands repeat full coordinates, which can be shorter for a shape whose points are far apart. A good optimiser does not choose one convention for the whole file; it chooses per command, and it also replaces a line whose vertical delta is zero with h or whose horizontal delta is zero with v.

The saving is not only in command letters. Relative numbers are often smaller, and small numbers need fewer characters after rounding. On a typical icon the difference between a careless and a careful path string is five to fifteen percent of the whole file, which matters when the icon is repeated in a sprite.

Smooth curves and their hidden control point

S and T assume a reflected control point. The reflection is computed from the previous curve's last control point, mirrored through the current point. If you convert S to C you must compute that reflected point yourself, or the curve changes shape. An optimiser that only changes case and number spelling can leave S alone safely; one that converts command types must carry the reflection.

Arcs are the fragile part

An arc has seven arguments, two of which are flags. Because the flags are single digits, the parser allows them without separators, and several tools historically produced strings that were ambiguous. When rewriting, keep a separator after the rotation and after each flag unless you are certain the grammar permits omission. If a path contains arcs and the optimised version looks wrong, the arc flags are the first thing to inspect.

Finally, Z does more than draw a line back: it joins the subpath so stroke joins and fills behave correctly. Removing it because the start and end points coincide changes the join at that corner. Keep Z when the original had it.

Sources

Questions

Why do two paths that look identical have different d strings?

The same outline can be described with absolute or relative commands, with line segments or curves, and with different starting points. Browsers render them the same. Optimisers rewrite the string into an equivalent but shorter form, which is why the file changes while the picture does not.

What do the two flags in an arc command mean?

In A rx ry rotation large-arc-flag sweep-flag x y, the large-arc flag chooses the longer of the two arcs that fit the ellipse and the sweep flag chooses clockwise or counter-clockwise. They are single digits, not numbers with decimals, and swapping one flips the curve to the other side of the line between the endpoints.

Can I use percentage coordinates in a path?

No. Path data accepts user units, not percentages. Percentage lengths are allowed on geometry attributes such as width or cx, but a d attribute must be numbers. For responsive sizing, keep the drawing in a viewBox and let the viewBox scale instead.

Paste a path into the optimizer and compare the absolute and relative output byte for byte.

Open the optimizer

Written against the W3C SVG specifications, MDN and the React and WCAG documentation; every sample in the examples can be pasted into the optimizer linked above.

Back to the guides