SVG Optimizer

Shrink and sanitise SVG files: strip editor junk and scripts, round numbers, minify paths.

An .svg or .svgz file, max 5 MB. Alternatively paste the SVG code below.

When you run the tool, this file is uploaded to our server, processed and then deleted. The files the tool creates stay on our server for about 2 hours: download them to keep them, or save them to your Google Drive.

More options

Coordinates and lengths are rounded to this many decimals. 1–3 is usually invisible; transforms keep two more.

Try an example: ·

More about this tool

Part of Reelcraft Audio, video & images

How it works

Optimises an SVG file in your choice of steps and shows how many bytes each one saved: removes comments, metadata and Inkscape/Illustrator editor data, hidden and empty elements, rounds numbers, rewrites path data in its shortest form and collapses whitespace. It also removes scripts, event handlers and external references, so the result is safe to embed.

  • The SVG is parsed by a strict built-in XML parser (no external entities; internal DOCTYPE entities are expanded once with a size cap, which blocks "billion laughs" files). The document is re-serialised after every step, and the byte count before/after each step is reported.
  • Security (always on): removes <script>, <foreignObject>, <iframe>/<embed>/<object>, all on* event handlers, javascript: links, xml:base, CSS @import and url() references to other files, external href on <use>/<image>/<feImage> (raster data: URIs are kept), and animations that change href or event attributes. Links in <a> may point to http(s) or mailto only.
  • Clean-up: comments, XML declaration, DOCTYPE and processing instructions; <metadata>, RDF and editor namespaces (Inkscape, Sodipodi, Illustrator, Sketch, Serif, Figma); elements with display:none that nothing references; unreferenced children of <defs>; empty groups, and groups without attributes are unwrapped; unused namespace declarations, version and baseProfile.
  • Numbers in geometry attributes are rounded to the chosen decimal places (transforms to two more) with leading zeros dropped. Path data is re-written per segment in whichever of absolute or relative form is shorter, lines become H/V where possible, repeated command letters are omitted, and relative values are computed from the rounded current point so errors do not accumulate.
  • Whitespace between elements is removed except inside text elements and xml:space="preserve". Removing width/height keeps (or creates) the viewBox so the graphic still scales.
  • The optimised SVG is offered as a download (served as an attachment, never rendered on this site).

Check the optimised file visually: very low precision can shift shapes, and removing width/height changes how some programs size the image.

Use this tool in an app

These free programs for your browser have this tool built in, next to everything else the task needs.

  • Reelcraft Audio, video & image batch studio

    Audio, video & image batch studio: cut, convert, compress, subtitle, reframe

    Open Reelcraft

Related tools

  • Image Compressor – Shrink JPG, PNG, WebP, AVIF or GIF images: convert, resize, strip metadata and compare sizes.

How to use the SVG Optimizer

Shrink SVG files from Inkscape, Illustrator or Figma, strip scripts and editor junk safely, and see exactly how many bytes each step saved.

What it is for

SVGs exported from design tools carry a lot of baggage: editor namespaces, metadata, comments, hidden layers, numbers with six decimal places and verbose path commands. That costs bytes on every page view. An SVG can also contain scripts and event handlers, so an SVG from an unknown source isn't safe to put on your site as is.

This optimiser runs a fixed sequence of steps and shows the size after each one. The security clean-up always runs: it removes <script>, on… handlers, javascript: links and references to external files. The size steps can be adjusted: rounding precision, path minification, removal of hidden elements, and optionally width/height for responsive icons.

It doesn't simplify shapes, convert text to paths or rasterise anything.

Worked example

The first example is a typical Inkscape export (999 bytes) with a comment, a sodipodi:namedview, empty RDF metadata, an onload="alert('hi')" on the root, a <script>, a hidden circle, an empty group and coordinates like 10.123456. With precision 2 and the defaults, the result was:

"SVG optimised from 999 B to 215 B (78.5% smaller; gzipped 533 B → 177 B); security findings removed: 2."

The biggest single saving came from metadata and editor data (360 bytes), then comments and the XML declaration (111), hidden elements (87) and path minification (75). The path M 60.000000 10.000000 L 110.000000 10.000000 … became M60 10h50V40H60z. The two security findings were the onload handler and the <script>. The final markup was a single line with one rect and one path.

The second example removes width and height from a 24×24 icon at precision 1: 172 B → 121 B. The viewBox="0 0 24 24" stays, so the icon scales to whatever size your CSS gives it.

How to read the result

  • Before / After / Saving: raw bytes. Gzipped after is closer to what actually goes over the network if your server compresses SVG.
  • Bytes saved per step shows where the weight was. If almost everything came from "Metadata and editor data", exporting as "plain SVG" from your editor would have done most of the job.
  • Security: removed content lists every element or attribute that was removed. If it isn't empty, check that the graphic didn't rely on it, for example for a hover animation.
  • Optimised SVG is the final code, ready to paste inline.

Tips and common mistakes

  • Compare the result visually. Precision 1–3 is usually invisible, but precision 0 on a small icon (24 px) can visibly shift curves.
  • Transforms keep two more decimals than geometry, because a rounded scale or rotation multiplies the error.
  • Only remove width/height when the SVG is sized by CSS. As an <img> without width and height, some browsers and email clients show it at 300×150 or full width.
  • Keep your editable master file. The optimised version drops layer names and editor data you may want later.
  • If an element you need disappears, check whether it was display:none or an unused <defs> entry. Switch off "Remove hidden elements" for sprite sheets whose symbols are only referenced from other files.
  • An empty security table doesn't make a file trustworthy in every context. It only means none of the patterns the tool checks for were found.

FAQ

Is it safe to optimise an SVG from an unknown source?

The tool parses it with a strict XML parser that blocks external entities and "billion laughs" files, removes scripts and external references, and serves the result only as a download. Still, review files from untrusted sources before you publish them.

Why is my gzipped saving smaller than the raw saving?

Gzip already compresses repetitive text like long decimals and namespace prefixes well. The raw saving overstates the network gain. Look at the gzipped figure for that.

Does it support .svgz?

Yes. Compressed SVGZ files are accepted as input (up to 5 MB). The output is a plain .min.svg.

Will it break CSS classes or IDs?

IDs and classes are kept. Only unused namespace declarations, editor attributes and unreferenced definitions are removed.

Guide last updated:

For scripts and AI agents

  • JSON API: POST https://svgoptimizer.usefulweb.site/api/v1/calculate (same calculation as this page)
  • Interface description: OpenAPI 3.1 · AI guide: llms.txt
  • MCP server (Streamable HTTP): https://svgoptimizer.usefulweb.site/mcp · tool name svg_optimizer
Example request
curl -s -X POST https://svgoptimizer.usefulweb.site/api/v1/calculate \
  -H 'content-type: application/json' \
  -d '{…see OpenAPI examples…}'
Feedback · ideas & bug reports welcome