SVG Optimizer
Image Tools · Added
An icon exported from a design tool carries the editor's fingerprints: a generator comment, an RDF metadata block, namespaced attributes no renderer reads, and coordinates written to seven decimal places. None of it draws anything. This removes it in your browser, rounds the geometry to a precision you choose, and shows you the file it produced rather than describing it.
Optimised SVG
- Original
- 762 B
- Optimised
- 329 B
- Saving
- 57%
4 elements kept
Preview
Percent-encoding, not Base64 — for SVG it is the smaller of the two.
Everything happens in this tab — the markup is never sent anywhere. The preview is the real output, so what you see is what the downloaded file draws.
How to use the svg optimizer
- 1Paste your SVG markup, or choose an .svg file — it is read in this tab, not uploaded.
- 2Leave the default switches on for a safe clean-up: comments, editor data and scripts go, the drawing stays.
- 3Set the coordinate precision. Two decimal places is invisible on an icon and is where most of the saving comes from.
- 4Check the preview, then copy the markup, download the file, or take the CSS data URI.
Examples
An exported 24-pixel icon
- Input
- 762 bytes: an XML declaration, a generator comment, an rdf:RDF metadata block, an inkscape:label, and coordinates at seven decimal places
- Result
- 329 bytes — 57% smaller, with the title element and both paths untouched
The drawing is byte-identical in the preview; only things that never rendered were removed.
An SVG carrying script
- Input
- <svg onload="alert(1)"><script>…</script><circle r="4.123456"/></svg>
- Result
- The script element and the onload attribute are removed, r becomes 4.12, and both removals are reported above the output
Inlining an icon in CSS
- Input
- A cleaned 20-line icon
- Result
- background-image: url("data:image/svg+xml,%3Csvg…"); — percent-encoded rather than Base64
About the svg optimizer
Where the bytes actually are
In a typical exported icon, roughly half the file never draws. The generator comment, the RDF metadata block describing the licence, the editor's own namespaced attributes recording layer names and tool settings, and the XML declaration are all inert once the file reaches a browser.
The other half is precision. A design tool that computes a point as 12.000000000000002 writes it out in full, and every one of those digits is a byte served to every visitor. Rounding to two decimal places on a 24-pixel canvas cannot move a point by more than a hundredth of a pixel, and it is usually the single largest saving in the file.
What it does not do is change how the file compresses. Gzip and Brotli already handle the repetition well, so a 57% saving on the raw bytes is a smaller saving over the wire — real, but not the same number. The figures shown here are raw bytes, which is the honest thing to measure without knowing your server's settings.
Inline, or serve as a file?
A data URI saves a request, which matters for a small icon that appears on every page. It also cannot be cached separately, so the same icon inlined on ten pages is downloaded ten times, and it cannot be styled with CSS the way an inline <svg> element can.
The rough dividing line: inline small, static, ubiquitous icons; serve anything over a couple of kilobytes, anything that changes independently of the page, and anything you need to recolour with currentColor. The tool warns when a data URI passes 32 KB, which is well past the point where a separate file is the better answer.
SVG as an attack surface
Any site that accepts an uploaded SVG and shows it back has to decide what to do about script. An SVG rendered through an <img> tag is inert — scripts do not run and external references do not load — which is why the preview on this page uses one. An SVG inlined into the markup is fully live.
That is the reason the two are not interchangeable, and the reason this tool reports what it removed rather than removing it quietly. If you are cleaning a file that came from outside your team, the count of scripts and handlers is the more useful output on the page.
It is worth being exact about the limit of that, though. Removing script tags and on-event attributes covers the usual cases and not the unusual ones: a javascript: link, an external reference, a style block that imports something. This is a cleaner, and a cleaner is not a sanitiser. For files uploaded by strangers, sanitise on the server with a library built for it and serve the result from an origin that is not your application.
Frequently asked questions
Will optimising change how the SVG looks?
Why does it strip scripts by default?
Does this make an untrusted SVG safe to inline?
Are ids and class names safe?
Why a percent-encoded data URI instead of Base64?
Does it handle every SVG file?
Related tools
Image to Base64
Image Tools
Turn an image into a Base64 data URI ready to paste into CSS or HTML.
XML Formatter
Developer Tools
Indent or minify XML and check it is well-formed, without disturbing mixed content or CDATA.
Favicon Generator
Image Tools
Generate a full favicon set at every size a modern site needs.
Image Color Picker
Image Tools
Click any point in an image to read its colour, and pull out the palette behind it.