01What is SVG Optimizer?
SVG files exported from design apps carry a lot of baggage. You get an XML prolog, generator comments, Inkscape layer labels, empty groups and coordinates with six decimal places. None of it changes the picture, but all of it ships to your users. SVG Optimizer strips that baggage with a fixed list of text-level passes that run on the markup in your browser tab. Here is what it does, in order. It removes XML comments, the <?xml ?> declaration, any DOCTYPE and <metadata> blocks. It drops Inkscape's sodipodi:namedview element plus every inkscape: and sodipodi: attribute. Namespace declarations such as xmlns:inkscape go only when nothing left in the file uses that prefix. That rule matters: xmlns:xlink stays as long as an xlink:href remains, because the XML Namespaces spec requires every used prefix to be declared. Next it removes empty attributes like class="", shortens six-digit hex colours to three digits (#FF0000 becomes #F00) and collapses whitespace runs to a single space. Colour shortening only touches fill, stroke, stop-color, flood-color, lighting-color and color, so an id that happens to look like a colour is left alone. Whitespace is kept if the file uses xml:space="preserve". Then it deletes empty <g> groups (nested ones too) and empty <title> or <desc> elements. Default values get careful treatment. opacity="1" is always removed because opacity isn't inherited. fill-opacity="1", stroke-opacity="1" and fill-rule="nonzero" are inherited properties in the SVG spec, so a child's explicit default can override its parent. The tool removes those only when no element in the file sets a different value. Finally, decimals with four or more places in attribute values are rounded to three, while ids, classes, links and font names are skipped. A quick example: a 24 by 24 Illustrator export with a generator comment, an empty group and the path M12.000004 2.123456L22 21.5H2z comes out with no comment, no prolog, fill="#F00" and the path M12 2.123L22 21.5H2z. The log lists each pass with the characters it saved, such as "Rounded numbers to 3 decimals (-10 chars)". Your markup never leaves the page. The preview draws the result as an <img>, so scripts or event handlers inside a pasted file can't run. Be clear on the limits, though. This is regex cleanup, not a parser like SVGO. It won't merge paths, convert shapes, rewrite path commands, inline styles or rename ids. A hand-written icon may not shrink at all.
Frontend developers who paste icons exported from Figma, Illustrator or Inkscape into their code and want the editor leftovers gone first. The tool runs entirely in your browser, so your data never leaves your device.
02How to use SVG Optimizer
- Paste your markup into the Input SVG box. Its size appears next to the label
- Click Optimize
- Read the size line at the top, which shows the original and optimized size and the percentage saved, or No change
- Open the Optimization Log to see which passes ran and how many characters each one removed
- Keep Show preview ticked and compare the drawing with your original
- Click Copy on the Optimized box to take the result
03Worked examples
- Input:
<?xml version="1.0" encoding="UTF-8"?> <!-- Generator: Adobe Illustrator --> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <g></g> <path fill="#FF0000" d="M12.000004 2.123456L22 21.5H2z"/> </svg> - Result:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path fill="#F00" d="M12 2.123L22 21.5H2z"/> </svg> Log: Removed comments (-37 chars), Removed XML declaration (-38 chars), Shortened hex colors (-3 chars), Collapsed whitespace (-5 chars), Removed empty groups (-7 chars), Rounded numbers to 3 decimals (-10 chars) - 12.000004 rounds to 12 and 2.123456 to 2.123. The leftover spaces come from collapsing runs to one space, not removing them.
- Input:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="..." xmlns:sodipodi="..."><sodipodi:namedview id="nv" pagecolor="#ffffff"/><g inkscape:label="Layer 1" inkscape:groupmode="layer"><circle cx="5" cy="5" r="4"/></g></svg> - Result:
<svg xmlns="http://www.w3.org/2000/svg"><g><circle cx="5" cy="5" r="4"/></g></svg> Log: Removed editor data, Removed unused namespace declarations - Namespace URLs shortened to ... here for space. The <g> stays because it is not empty.
- Input:
<svg xmlns="http://www.w3.org/2000/svg"><rect class="" width="4" height="4" fill-rule="nonzero"/><title></title></svg> - Result:
<svg xmlns="http://www.w3.org/2000/svg"><rect width="4" height="4"/></svg> Log: Removed empty attributes (-9 chars), Removed empty title/desc (-15 chars), Removed default values (-20 chars) - fill-rule="nonzero" goes because nothing else in the file sets a different fill-rule.
- Input:
<svg xmlns="http://www.w3.org/2000/svg"><g fill-opacity="0.5"><rect fill-opacity="1" width="4" height="4"/></g></svg> - Result:
Unchanged. Log: No optimizations needed - The child's fill-opacity="1" overrides the parent's 0.5, so removing it would change the drawing. The tool keeps it.
- Input:
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><use xlink:href="#a"/></svg> - Result:
Unchanged. Log: No optimizations needed - xmlns:xlink stays because xlink:href still uses the prefix.
- Input:
<svg><rect id="ff0000aa" fill="#aabbcc" stroke="#aabbcd"/></svg> - Result:
<svg><rect id="ff0000aa" fill="#abc" stroke="#aabbcd"/></svg> - Only colours made of paired digits shorten, and the colour-like id is left alone.
04Common use cases
- Cleaning an Inkscape export that still carries sodipodi:namedview, layer labels and unused namespace declarations before committing it to a repo
- Trimming an Illustrator or Figma icon export with six-decimal path data before pasting it inline into a React component
- Checking what a pasted SVG actually contains by reading the optimization log, for example spotting a leftover <metadata> block
- Shrinking a small logo before turning it into a CSS data URI, where every character counts in the stylesheet
- Removing empty <title> and <desc> placeholders that an export added, so screen readers don't announce blank labels
- Getting a quick before and after byte count for an SVG in a pull request review without installing SVGO
05Tips
- If the log says No optimizations needed, the file is already lean for this tool's rules. The next step is SVGO in your build, not pasting it again
- Rounding to three decimals is invisible on a 24 by 24 icon, but on a tiny viewBox such as 0 0 1 1 a step of 0.001 is a bigger share of the drawing, so check the preview
- An explicit fill-opacity="1" survives when some other element sets fill-opacity to a different value. That is on purpose, since the child may be undoing its parent's transparency
- Ids are never renamed or removed, so CSS selectors, SMIL animations and url(#gradient) references keep working after the cleanup
- Whitespace runs become one space rather than nothing, so a single newline between tags can remain. That is harmless and gzip handles it well
06Related concepts
SVGO, SVG sprites, viewBox, Path data.
Frequently Asked Questions
What is SVG Optimizer?
SVG Optimizer is a free, browser-based developer tool on AIDToolStack. Optimize SVG code by removing comments, metadata, and unnecessary attributes. Preview and compare sizes. It requires no installation or sign-up and works entirely in your browser.
Is SVG Optimizer free to use?
Yes. No sign-up, no fees and no usage cap.
Does SVG Optimizer store my data?
No. It runs in your browser; nothing is uploaded.