How to use the SVG optimizer
- Paste SVG code or choose an
.svgfile (up to 5 MB). - Set the decimal places: 2 is right for icons, 3 for detailed illustrations and maps.
- Review the options. The defaults are safe for almost every file.
- Compare the previews of the original and optimized versions.
- Copy or download
optimized.svg, or copy the CSS data URI to embed a small icon in a stylesheet.
What the optimizer does
- Removes editor data:
<metadata>, Inkscape and Sodipodi elements, editor attributes and namespaces such asinkscape:andsketch:, anddata-name. - Removes comments, except those starting with
<!--!, which conventionally hold licences. - Removes unused IDs, keeping any referenced by
url(#…),href="#…"or animation timing. - Drops default attributes:
fill-opacity="1",stroke-width="1",fill-rule="nonzero",versionand similar. - Collapses groups: empty
<g>and<defs>disappear, and attribute-free groups pass their children to the parent. - Rounds numbers in coordinates, sizes, points, transforms and path data, and writes
0.5as.5. - Compacts path data:
M 10.000,20.000 L 30,40becomesM10 20L30 40. Arc flags are parsed by position, because they can be written without spaces and must never be merged. - Adds a viewBox from width and height if it’s missing, so the SVG can scale.
- Shortens colours like
#ffffffto#fff, and modernisesxlink:hreftohref.
Worked examples
Example 1: an editor export
Load the sample sunrise icon. It shrinks by more than half: the XML declaration, comment, metadata, layer group, editor attributes and default values disappear, and numbers like 28.123456 become 28.12. The previews look identical.
Example 2: icons for a sprite
For an icon set, turn on Remove width/height so every icon scales with CSS, keep titles off if your icon component adds an aria-label, and use precision 1 or 2. Small icons often end up under 300 bytes.
Example 3: an untrusted upload
Paste an SVG containing <script> or onload="…". The checks report what was found and removed. For user uploads on your own site, also sanitise on the server and serve SVGs with a restrictive Content-Security-Policy.
Getting the most out of optimization
Optimization removes waste, but the biggest wins come from the artwork itself: fewer nodes, simplified paths and merged shapes. After optimizing, serve SVGs with gzip or Brotli compression. Text-based SVG often compresses by another 60–70%.
Common mistakes
- Too little precision on large or detailed drawings, which shifts shapes. Increase the decimal places.
- Removing IDs that CSS or JavaScript uses. IDs referenced only from your own stylesheet or scripts aren’t visible to the optimizer; turn off Remove unused IDs in that case.
- Removing titles from meaningful graphics, which hides them from screen readers.
- Inlining large SVGs as data URIs. They can’t be cached separately; link them as files instead.