DevTools Pro · All tools · About

SVG Optimizer

About the SVG Optimizer

This SVG optimizer is an online SVG compressor that shrinks SVG files by removing editor metadata, comments, empty groups and extra whitespace, and by rounding coordinates to the number of decimal places you choose. It shows the original size, the optimized size and the percentage saved, plus a before-and-after preview, and everything runs in your browser.

Why SVG files from design tools are bloated

Inkscape, Illustrator, Sketch and Figma save extra data that browsers never use: <metadata> blocks, sodipodi:namedview settings, inkscape:label attributes, layer IDs, comments and the XML declaration. Coordinates are often written with six decimal places, such as 60.000000.

None of this affects how the image renders, but it can make up half of a small icon's file size. Removing it speeds up page loads and makes inline SVG easier to read.

What this optimizer changes

Remove comments deletes <!-- --> comments inside the <svg> element. Remove metadata and editor data deletes <metadata>, processing instructions, elements and attributes from known editor namespaces (Inkscape, Sodipodi, Adobe, Sketch, Figma, Serif, Dublin Core, RDF), data-name attributes and the legacy root attributes version, xml:space and enable-background. Remove whitespace between tags deletes the indentation and line breaks between elements, but not inside <text>, <title>, <desc>, <style> or <script>.

These are always applied: empty attributes are dropped, unused namespace declarations are dropped, the XML declaration and anything before the <svg> element (such as a leading comment) are not written, and empty groups are deleted.

Path data is rewritten compactly, so M 40.000000,62.500000 L 54.333333,76.666667 becomes M40 62.5L54.33 76.67. Plain groups with no attributes are unwrapped, and empty <g> and <defs> are deleted.

It does not merge paths, convert shapes, or touch <style> and <script> contents, so the result stays predictable. Deeper transforms such as merging paths are not part of this tool.

Choosing decimal places

Two decimal places are a safe default for icons and illustrations drawn on a typical 24 to 1000 unit canvas. Zero or one decimal place saves more bytes but can shift small shapes or curves slightly, so check the Before / after preview.

For very small viewBoxes, such as 0 0 1 1, keep three or four decimals, because each unit spans the whole image.

IDs, titles and accessibility

IDs referenced by url(#id), href="#id" or a <style> block are always kept, so gradients, clip paths, masks and <use> elements keep working. Remove unused IDs only strips IDs that nothing points to.

A <title> inside an SVG acts as its accessible name for screen readers. Leave Keep <title>/<desc> on for meaningful images, and turn it off only for purely decorative icons.

How to Use the SVG Optimizer

  1. Paste SVG markup into Original SVG, click Upload to choose a .svg file, or click Example to load a sample Inkscape file.
  2. Set Decimal places (0 to 4) and switch Remove unused IDs, Keep <title>/<desc>, Remove comments, Remove metadata and editor data and Remove whitespace between tags on or off. The result updates live.
  3. Check the Original, Optimized and Saved figures and the Before / after previews, then click Copy or Download to get the optimized SVG.

SVG Optimizer Examples

Round coordinates and drop a comment

Default options (2 decimal places). The comment is removed, the title is kept and the path data becomes compact.

Input:

<svg width="24" height="24" viewBox="0 0 24 24"><!-- icon --><title>Check</title><path d="M 5.000 12.500 L 10.123456 17.5 L 19 7.25" fill="none" stroke="#000" stroke-width="2.000"/></svg>

Output:

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><title>Check</title><path d="M5 12.5L10.12 17.5L19 7.25" fill="none" stroke="#000" stroke-width="2"/></svg>

Clean up a design-tool export

Default options. Layer ids, attribute-less groups, whitespace and trailing zeros go, and the missing xmlns is added so it works as a standalone file.

Input:

<svg width="32" height="32" viewBox="0 0 32 32" fill="none">
  <g id="Icon">
    <g id="Group">
      <rect id="Rectangle 1" x="4.000000" y="4.000000" width="24.000000" height="24.000000" rx="6.500000" fill="#0D99FF"/>
    </g>
  </g>
</svg>

Output:

<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32" fill="none"><rect x="4" y="4" width="24" height="24" rx="6.5" fill="#0D99FF"/></svg>

Keep referenced IDs, remove unused ones

Remove unused IDs on. c is used by clip-path, so it stays; unused is removed.

Input:

<svg viewBox="0 0 10 10"><defs><clipPath id="c"><rect width="5" height="5"/></clipPath></defs><rect id="unused" width="10" height="10" clip-path="url(#c)"/></svg>

Output:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><defs><clipPath id="c"><rect width="5" height="5"/></clipPath></defs><rect width="10" height="10" clip-path="url(#c)"/></svg>

Common Errors

The output shows an "Invalid SVG/XML" message.
The markup is not well-formed XML, for example a tag that is not closed or closed in the wrong order. Fix the tag named in the message and the output returns.
The message says "The root element must be <svg>".
Paste the whole <svg>...</svg> element. Markup that starts with another element, such as a <div> wrapper, is rejected.
Small shapes shift or curves look slightly different.
Raise Decimal places to 3 or 4. Zero or one decimal place rounds coordinates coarsely, which matters most on small viewBoxes.
A gradient, mask or clip path stopped working.
Turn off Remove unused IDs. The tool only sees references in attributes and <style>, not ones built in JavaScript or external CSS.
A path with invalid data is left unchanged.
Path data that cannot be parsed is kept exactly as written and only the other attributes are optimized. Correct the d attribute to get it compacted.

Frequently Asked Questions

Will optimizing change how my SVG looks?
Not at 2 or more decimal places in typical files. Only number rounding can change geometry, and the Before / after preview lets you confirm the result.
How much smaller will my SVG get?
It depends on the source. The built-in Example, a small Inkscape badge, drops from 1.43 KB to 478 B (67.3% saved) at 2 decimal places. Editor exports often shrink by half or more, while SVGs that were already minified may only lose a few percent.
Is this the same as SVGO?
No. This is its own small, conservative optimizer that works in your browser and covers the most common savings. It does not merge paths, convert shapes or use SVGO option names.
Why did my gradient or icon break?
Referenced IDs are kept, but references built in JavaScript or external CSS cannot be detected. If something breaks, turn off Remove unused IDs.
Are my SVG files uploaded, and is it safe to preview SVGs with scripts?
Nothing is uploaded: parsing and optimization use the browser's DOMParser and XMLSerializer. Previews render through an <img> tag, which never runs scripts inside an SVG. Script elements are kept in the output, so review them before using the file.

Related tools