Web & CSS

SVG Optimizer

Paste, upload or drop an SVG to optimize, minify, format or validate it. Every change is listed, nothing is guessed on invalid input, and the before/after preview never runs a script.

Guide: How to Optimize SVG Safely: Smaller Files, Same Image

Drag and drop an .svg file here, or use Upload above
Ready.

What it does

Optimize (the default) removes comments, editor-only metadata (Inkscape/Sodipodi namespaces, <metadata>), the DOCTYPE and processing instructions, tidies whitespace, shortens lossless hex colors, and - only if you turn it on - rounds coordinate and size numbers to fewer decimal places. Every change made is listed under the output. Beautify and Minify reformat without removing anything. Validate checks that the XML is well-formed and reports the exact line and column of any problem.

Safe by design

  • A real XML-aware parser reads the file first - <script> and <style> content is treated as raw text, never as tags, and a DOCTYPE's internal subset (where XXE and "billion laughs" attacks live) is captured as inert text and never parsed or expanded.
  • If the SVG is not well-formed - an unclosed tag, a mismatched closing tag, a duplicate attribute - every mode reports the problem instead of guessing at a fix. XML has no browser-style error recovery, so this tool doesn't invent one either.
  • Text inside <text>, <tspan>, <title>, <desc>, <style> and <script> is never reformatted, since whitespace there can be meaningful.
  • The before/after preview renders through an <img> element using a data: URI - by the HTML specification, an SVG shown this way can never run a script, regardless of what the file contains. (An SVG can still reference external images or stylesheets; whether a browser fetches those inside an <img> varies, so the preview may show a broken image for such files - this tool itself never fetches anything.)
  • Nothing is uploaded anywhere; reading a file, or a drag-and-drop, happens entirely on your device.

Good to know

This does not rewrite path geometry (merging segments, converting curve types) or remove element ids - both are common in more aggressive optimizers but can silently break external CSS or JavaScript that targets those ids, or subtly change rendering, so they're left alone here. Numeric precision reduction is off by default and only touches attributes that are purely numeric (d, points, viewBox, coordinates, sizes) - never colors, ids or class names.

Example: 421 bytes to 289 bytes

The built-in example is a small SVG exported from an editor. Optimize reports “Original: 421 B → Optimized: 289 B (31% smaller)” and lists the 6 edits:

  • removed the XML processing instruction,
  • removed a comment,
  • removed the <metadata> element, which is editor-only data that is not rendered,
  • shortened three colours, for example #ff0000 to #f00 and #0000ff to #00f.
<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120" viewBox="0 0 120 120"><g id="layer1"><circle cx="60.000" cy="60.000" r="40.000" fill="#f00" stroke="#000" stroke-width="2.000"/><rect x="30.000" y="30.000" width="60.000" height="60.000" fill="none" stroke="#00f"/></g></svg>

Numbers such as 60.000 are left as written until you set a precision, because rounding changes the drawing slightly. In this example the group’s id was also kept. The other modes are Format, which only indents the code, Minify, which removes whitespace, and Validate, which checks that the file is well-formed SVG.

Frequently asked questions

Will my image look the same?

The edits listed in the example do not change what is drawn. Always compare the result visually, especially if you set a lower precision.

How do I use an optimized SVG in CSS or HTML?

Paste it inline, or turn it into a data URI with Image to Base64.

Is my file uploaded?

No. The SVG is optimized in your browser.

Privacy

This tool runs entirely in your browser, including for large files handled by a background Web Worker. Your SVG is not sent to a server.

Share this tool

Your data is not included in this link.