Free SVG Minifier & Optimizer — Shrink SVG Files Online
Minify and optimize SVG code in your browser — strip editor metadata, round decimal precision, shorten hex colors, and flag unsafe scripts. No upload, batch export as .zip.
What it does
Paste raw SVG markup or drop one or more .svg files, and this tool strips out everything a design tool like Illustrator or Inkscape leaves behind — comments, <title>/<desc> tags, editor-only namespaced attributes — while rounding coordinate precision and shortening hex colors. Most icon exports shrink by 40–70% with no visible difference. Everything runs locally in your browser; files are never uploaded anywhere.
How it works
The minifier parses your SVG as real XML (not just text find-and-replace), walks the resulting tree, and removes or rewrites specific things:
- Editor cruft — Inkscape and Sodipodi namespaced elements and attributes, Adobe Illustrator’s legacy
<!ENTITY>declarations, and now-unusedxmlns:declarations once their last consumer is gone. - Coordinate precision — every numeric value inside
d,viewBox,transform, and other geometry attributes is rounded to a configurable number of decimal places, which is usually where most of the byte savings come from on hand-exported icons. - Hex colors — six-digit colors like
#ffcc00collapse to#fc0wherever the two digits in each channel already match. - Empty groups —
<g>and<defs>elements left with nothing inside (a common byproduct of layer panels) are pruned in repeated passes, since removing one empty group can leave its parent empty too.
Because parsing goes through the browser’s real XML parser, legacy Illustrator exports with custom DOCTYPE entities parse correctly instead of breaking — a common failure mode in regex-only minifiers. Text content inside <text> and <tspan> is never touched, since whitespace there is often meaningful.
The before/after preview renders each version as an <img> with a data: URI, which is why pasting an SVG with an embedded <script> here is safe to preview — browsers never execute script tags loaded this way. If your file does contain a <script>, the tool flags it and offers a one-click toggle to strip it entirely, which is worth doing before embedding a downloaded SVG (from an icon site, a client, or anywhere else you don’t fully trust) into your own site.
How to use it
- Paste your SVG source into the left-hand editor, or switch to “Upload files (batch)” and drop one or more
.svgfiles. - Pick a preset — Safe only touches precision, Balanced is a sensible default, Aggressive also strips unused ids and
<script>tags — or adjust the individual toggles yourself. - Check the before/after preview and the byte-savings readout in the sidebar.
- Copy the minified code, download the single file, or download the whole batch as a
.zip.
FAQ
Will this change how my SVG looks? No — every default transformation is lossless for rendering. Rounding decimal precision to 2 places, for example, moves shapes by a fraction of a pixel at most, well under what’s visible. The one optional exception is “Remove unused ids,” which is off by default because an external stylesheet might target one of those ids even though nothing inside the SVG references it.
Is it safe to paste an SVG I got from somewhere else? The preview render can’t execute embedded scripts (it uses the same safe rendering path as <img> tags), but the underlying file can still contain one. Turn on “Strip scripts” before you use the file anywhere it might get treated as trusted content.
Why did my file barely shrink? Clean, code-generated SVGs (from a design tool’s “export optimized” option, for instance) don’t have much editor metadata to remove. You’ll see the biggest gains on files hand-exported from Illustrator or Inkscape with default settings.
Does this work on SVGs with embedded raster images? Yes, but a <image> element’s own base64-encoded picture data isn’t re-compressed by this tool — only the surrounding SVG markup is. If your file is mostly a huge embedded PNG, converting that image separately with an image compressor first will do more for file size than SVG minification alone.
What happens to text inside my SVG? It’s left completely alone, including whitespace — minification only ever touches structural markup, comments, and numeric attribute values, never <text>/<tspan> content.
Related tools
If your SVG came from a screenshot or photo rather than a vector export, run it through Image → SVG first to trace it into paths. Once you’re happy with a minified icon, SVG → CSS will convert it into a background-image-ready CSS snippet, and the SVG Extractor can pull inline SVGs back out of an HTML page if that’s where yours started.