SVG Optimizer
Minify and clean up SVG markup — collapse whitespace, strip comments and editor metadata, normalize tags. Path data is never rewritten, so the rendered image is unchanged. Runs in your browser; nothing is uploaded.
About this tool
SVG Optimizer shrinks and cleans up SVG markup for faster delivery and tidier source, without ever changing how the image looks:
- Collapses whitespace — indentation and newlines between tags are removed and runs of whitespace inside tags are normalized.
- Removes comments —
<!-- … -->blocks are stripped (leave Remove comments off to keep them). - Strips the XML prolog — the
<?xml … ?>declaration and<!DOCTYPE …>are removed; they're not needed for inline or web SVG. - Drops editor metadata —
<metadata>blocks and Inkscape/Sodipodi elements and attributes (inkscape:*,sodipodi:*, and their unusedxmlnsdeclarations) are removed.
Optional, off by default:
- Remove id & class attributes — handy for icons, but skip it if your CSS, JS
or
<use>references them. - Remove root width/height — only applied when the
<svg>has aviewBox, so the graphic scales responsively without losing its aspect ratio.
It's intentionally safe:
- Path data and numbers are never rewritten, so the rendered image is identical — this is not a lossy compressor.
<script>,<style>and<text>keep their contents verbatim, so CSS, scripts and visible text aren't broken.- Attribute values are never touched.
Everything runs locally in your browser via WebAssembly — your SVG is never uploaded.
FAQ
Will optimizing change how my icon looks?
No. This is a lossless cleaner: path d data, coordinates and numbers are
never rewritten or rounded, so the rendered image is byte-for-byte identical
in appearance. It only strips safe-to-remove cruft like comments, editor
metadata and structural whitespace.
Why are id/class and width/height left in by default?
Both removals can break real usage, so they're off by default. Deleting
id/class breaks any CSS, JavaScript or <use xlink:href="#…"> that
references them. Removing the root width/height only happens when a
viewBox is present (so the graphic still scales), but some layouts rely on
the intrinsic size — enable each only when you know it's safe.
Does it touch my inline <style>, <script> or <text>?
No — the contents of <style>, <script> and <text> are kept verbatim.
Whitespace inside <text> can be visually significant, and collapsing CSS or
JS could break it, so those elements are passed through untouched. Attribute
values everywhere are also left alone.
What exactly gets stripped as "editor metadata"?
With Remove editor metadata on (the default), <metadata>, RDF blocks and
Inkscape/Sodipodi elements are dropped, along with their attributes
(inkscape:*, sodipodi:*) and the now-unused xmlns:inkscape,
xmlns:sodipodi, xmlns:rdf, xmlns:cc, xmlns:dc declarations. The core
xmlns needed to render the SVG is always kept.
Developer & Automation Access
Run it from the terminal
Same engine as this page, headless — via the gizza CLI:
gizza tool svg-optimize '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<!-- icon -->
<path d="M12 2L2 22h20L12 2z"/>
</svg>'New to the CLI? Get gizza →
Open it by URL
Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:
https://gizza.ai/tools/svg-optimize/?svg=%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%0A%20%20%3C%21--%20icon%20--%3E%0A%20%20%3Cpath%20d%3D%22M12%202L2%2022h20L12%202z%22%2F%3E%0A%3C%2Fsvg%3E&remove_comments=true&remove_metadata=true&remove_ids=true&remove_dimensions=trueMachine-readable descriptor: tool.json — title + parameters JSON Schema for agents.
