SVG optimizer

Choose an SVG to get a smaller file that draws the same picture. The size before and after and both pictures are shown, and the two are compared pixel by pixel.

Free, no account. The file is read by code running in your browser. It is not uploaded, and nothing about it is stored.

or drop it here, or paste. SVG code works too

How to optimise an SVG

  1. Choose your SVG, drop it on the box, or paste SVG code.
  2. Read the size before and after, and look at the two pictures. The line under them says whether they match pixel for pixel.
  3. Change the decimal places, or untick a step, if you want to keep something.
  4. Download the SVG, or copy the code.

What it takes out

  • Comments, the <?xml?> line and the DOCTYPE. A DOCTYPE that declares entities, as old Illustrator files do, has them written out in full first.
  • Editor data: <metadata>, and the elements and attributes that Inkscape, Illustrator, Sketch and other editors add in their own namespaces for their own use. No renderer reads them.
  • Namespace declarations that nothing uses once the editor data has gone.
  • Unused ids and definitions: ids that nothing in the file points to, and gradients, clip paths, masks, patterns, filters and markers that nothing uses.
  • Groups that do nothing: empty ones, and ones with no attributes, whose contents are moved up a level.
  • White space between elements and inside path data, style attributes and style sheets.
  • Digits: numbers are cut to the decimal places you choose, 0.5 becomes .5 in path data, and a colour such as #ffcc00 becomes #fc0.

Decimal places

Editors write coordinates with far more digits than any screen or machine can show: 120.00000, 47.262188. Cutting them is where most of the saving comes from, and it is the only step that can move anything at all, so it is the one you control.

The number is in the units of the viewBox. The tool suggests enough places to keep everything within 1/20,000 of the drawing’s longer side: 3 places for a 24 unit icon, 2 for a drawing 1,000 units wide. Shapes inside a group that is scaled up keep more places to match, and coordinates inside gradients, patterns, masks, clip paths and filters keep three more. In a path made of relative steps, each step is measured from where the rounded path has reached, so the error never adds up along the line.

What it leaves alone

  • Everything inside <text>. Spaces there can be part of the wording, so they are never touched.
  • <title> and <desc>, which screen readers use, and anything inside a <foreignObject>.
  • <symbol> elements and their ids. A file that draws nothing itself is treated as a sprite sheet that other files point into, and keeps every id and definition.
  • Ids and elements in a file with a script, and elements in a file whose style sheet picks by position (:first-child, +, ~). Removing them could change what the script or the selector finds. The tool tells you when this happens.
  • The shapes themselves. It does not merge paths, turn shapes into paths or rewrite path commands. Tools that do can save a little more, and now and then change the picture.

How much smaller

It depends on where the file came from. The sample on this page is a star in a ring, saved the way a vector editor saves it: 2,589 bytes. Optimised at the suggested 2 decimal places it is 764 bytes, 70% smaller, and the two pictures are identical. A file exported with a “minify” option, or one already optimised, has little left to remove.

Web servers usually send SVG compressed with gzip or Brotli, which already squeezes repeated white space well. Expect the saving over the wire to be smaller than the saving on disk, though still real: fewer digits and fewer elements compress to less.

Questions

Are compressing, minifying and optimising an SVG the same thing?

Near enough. Minifying means removing white space and comments. Optimising also removes what the picture does not need, such as editor data and spare digits. Both are what people usually mean by compressing an SVG, and this page does both. The result is still a plain .svg file that opens anywhere.

Will my SVG look different afterwards?

It should not, and you can check: both pictures are shown, and the page compares them pixel by pixel and tells you the result. If shortening the numbers ever shows, choose more decimal places.

Why were some ids kept?

An id stays when anything in the file points to it: a url(#…), an href, a rule in a style sheet. All ids stay when the file has a script, or draws nothing itself. If your web page’s own CSS or scripts find parts of the SVG by id, untick “Remove ids and definitions nothing uses”.

Will the smaller file still open in my cutting or drawing program?

It is standard SVG and nothing else. Path data is written in the compact form vector editors themselves write, where a minus sign can stand in for the space before it. If a program objects, untick “Shorten numbers and colours” and the path data is left as it was.

Is my file uploaded?

No. The optimiser is code that runs in your browser, on your device. The file never leaves it.

Related