What an SVG optimizer actually removes (and when to tell it not to)
If you export an SVG from Inkscape, Illustrator or Figma, a good part of the file is stuff the browser never uses to draw it. An optimizer like SVGO strips that out. Here's what typically goes, and the two cases where you should hold it back.
What gets removed
Editor metadata. Inkscape adds sodipodi: and inkscape: attributes and a <sodipodi:namedview> element with your zoom level and guides. Illustrator adds its own namespaces and a <metadata> block. None of it affects rendering.
Comments, the XML declaration and DOCTYPE. Inline SVG in HTML doesn't need <?xml version="1.0"?>, and the DOCTYPE is ignored.
Empty groups and hidden elements. Layers you emptied or hid still leave <g> tags behind.
Default attribute values. fill-opacity="1" or stroke="none" on elements where that is already the default.
What gets rewritten
Path data is where most of the savings usually are. A path like this:
<path d="M 10.000000,20.000000 L 30.000000,20.000000 L 30.000000,40.000000 Z" /> can become:
<path d="M10 20h20v20z"/> Same shape: absolute commands become shorter relative ones where that's smaller, horizontal and vertical lines use h and v, and trailing zeros go.
Numbers also get rounded to a precision you choose. Three decimal places is usually invisible on screen. Going lower makes the file smaller but can visibly shift small icons, so compare before and after.
When to tell it not to
- Your CSS or JavaScript targets IDs or classes inside the SVG. Optimizers may remove or shorten IDs and merge groups, and then
#logo-eyeor.spinno longer matches anything. Keep IDs, classes and structure for animated or scripted SVGs. - You need the file to stay editable. Strip the metadata from the copy you ship, not your source file, or your editor loses its layers and guides.
If you're running SVGO from the command line:
npx svgo logo.svg -o logo.min.svg --precision 3 A quick browser option
Disclosure: I run GoToolsOnline. Its free SVG Optimizer runs SVGO in your browser, lets you set the precision, has a "keep IDs, classes and structure" option, and shows before and after previews with the byte size, so you can check nothing moved before downloading.