Field guide for designers & developers
Clean SVG: smaller files, sharper icons, fewer surprises
An icon that renders in 300 bytes often ships at 6 KB, because the file still carries the design app’s private notes, coordinates to eight decimal places and layers nobody can see.
01Where SVG bloat comes from
SVG is XML, so design tools can store anything in it. Typical exports carry:
- Editor state: Inkscape’s
sodipodi:namedviewwith zoom level and window position, Illustrator’s private data, layer names ininkscape:labelordata-name. - Document metadata: RDF and Dublin Core blocks, generator comments, XML declarations and doctypes.
- Over-precise numbers:
12.345678901where12.35lands on the same pixel. - Verbose styling:
style="fill:#d97706;fill-opacity:1;stroke:none;stroke-width:0.26458"wherefill="#d97706"renders identically. - Structural leftovers: empty groups, single-child wrappers, unused gradients and clip paths from deleted layers.
None of it changes what the browser draws, but all of it is downloaded, parsed and, for inline SVG, kept in the DOM of every page.
02Precision without drift
Lowering precision is where most savings come from, and where naive minifiers break shapes. Path commands are often relative: each point is stored as an offset from the previous one. Round every offset independently and the errors add up, so a long outline slowly walks away from where it should end.
This tool converts every point to absolute coordinates first, rounds those, and only then works out the shortest way to write each segment, absolute or relative. Each point is within half a step of its true position no matter how long the path is. Choose precision from the size of the drawing:
| Artwork | Typical viewBox | Precision |
|---|---|---|
| UI icons | 0 0 24 24 | 2 |
| Logos, illustrations | 0 0 200–800 | 1–2 |
| Maps, charts, large artwork | 0 0 1000+ | 1 |
| Tiny icons drawn on a 1-unit grid | 0 0 1 1 | 4–5 |
03Reading path data
A path’s d attribute is a list of drawing commands. Uppercase letters use absolute coordinates; lowercase use offsets from the current point:
M 10 10 move to (10, 10)
h 30 line 30 to the right
v 20 line 20 down
L 10 30 line to (10, 30)
c 0 -5 ... cubic curve, control points relative
z close the shape
The optimizer picks absolute or relative per segment, whichever is shorter, uses H and V for straight horizontal and vertical lines, turns curves whose first control point mirrors the previous one into the S and T shorthands, drops repeated command letters, and removes every separator the grammar does not need: M10 10L20 20 becomes M10 10 20 20, and 0.5 -0.5 becomes .5-.5.
04Inline SVG, a file or a data URI
| Method | Best for | Trade-off |
|---|---|---|
| Inline <svg> | Icons styled with CSS, animated or interactive graphics | Not cached separately; repeats in every page’s HTML |
| .svg file | Logos and illustrations reused across pages | One request; cannot be recolored with CSS |
| Data URI | Small CSS backgrounds, patterns, list markers | Inflates the stylesheet; best under about 4 KB |
For SVG, URL-encoding beats base64: base64 adds a third to the size and compresses poorly, while URL-encoded SVG only escapes a handful of characters and stays readable. The tool swaps double quotes for single quotes so the result drops straight into url("…").
05SVG in React
JSX is not HTML: hyphenated attributes become camelCase, class becomes className, and inline styles must be objects. The generated component handles all of that and spreads props onto the root element:
import ArtisaneaMark from './ArtisaneaMark';
<ArtisaneaMark className="h-6 w-6 text-amber-700" aria-hidden="true" />
Turn on Use currentColor for single-color icons and they inherit the surrounding text color, so one component serves every theme, hover state and dark mode. Turn on 1em size and the icon scales with the font size of its parent.
06Export settings that help before you optimize
- Illustrator: File › Export › Export As › SVG, with Styling set to Presentation Attributes, Object IDs set to Minimal, and Responsive ticked.
- Inkscape: Save As › Optimized SVG, or Plain SVG at minimum. Inkscape SVG keeps all editor data.
- Figma: untick Include id attribute unless you need it, and outline text you do not want to depend on installed fonts.
- Everywhere: convert text to outlines for logos, and remove hidden layers before exporting; hidden layers still ship in the file.