SVG Minifier

Optimize SVG files with SVGO: remove metadata, collapse groups, and control number precision

Example
0 chars | 0 lines

What is an SVG Minifier?

An SVG minifier, also called an SVG optimizer, makes an SVG file smaller without changing how it looks. It removes comments, metadata, empty attributes, unused namespaces, and extra whitespace, shortens numbers in path data, and can merge redundant groups.

SVG files exported from design tools often carry a lot of this extra data. Smaller SVGs load faster and help Core Web Vitals when you use them as icons, logos, and illustrations. This tool uses SVGO, the optimizer behind many build tools, and runs in your browser.

How to Use This SVG Minifier

  1. Paste your SVG code into the input box, or click Example to load a sample.
  2. Choose your options. The table below explains each checkbox, and Precision controls decimal places.
  3. Click Minify SVG.
  4. Check the Preview. Make sure the optimized image still looks right.
  5. Copy Result or use Download .svg. Use Beautify if you want an indented version to read.

The Options Explained

Option What it does Good to know
Remove commentsDeletes XML comments such as <!-- Created with a design tool -->Low risk
Collapse groupsMerges <g> groups that add nothingKeep groups you target with CSS or JavaScript
Remove empty attrsDeletes attributes with empty valuesLow risk
Remove empty containersDeletes elements such as empty <g> or <defs>Low risk
Shapes to pathsConverts <rect>, <circle>, and similar shapes into <path>Often smaller, but you can no longer change a shape with attributes such as r or rx
Sort attributesPuts attributes in a consistent orderHelps gzip compress the file better
Remove unused namespacesDeletes namespace declarations nothing usesCommon in files from design tools
Remove XML declarationDeletes <?xml ... ?>Fine for inline SVG
Remove doctypeDeletes <!DOCTYPE ...>Fine for inline SVG
Clean up attribute valuesTidies whitespace and formatting inside attribute valuesLow risk
PrecisionRounds numbers in path data and numeric attributes to 1 to 5 decimal placesLower values make smaller files but can slightly distort curves

Precision: How Many Decimals to Keep

Precision sets how many decimal places are kept in numbers such as path coordinates and shape attributes. The default is 2 decimals, and trailing zeros are removed.

Precision Value 12.3456 becomes Best for
1 decimal12.3Small icons, smallest files
2 decimals12.35Most icons and logos
3 decimals12.346Detailed illustrations
4 decimals12.3456Large or precise artwork
5 decimals12.3456Maps and very precise artwork

Lower precision makes smaller files but can slightly distort curves, so check the Preview.

Example: Before and After Minifying

Input (330 bytes). Try it with the default options.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with a design tool -->
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
  <g>
    <rect x="2.000" y="2.000" width="20.000" height="20.000" rx="4.000" fill="#2563EB"/>
    <circle cx="12.000" cy="12.000" r="5.000" fill="#FFFFFF"/>
  </g>
</svg>

Output (199 bytes):

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><rect x="2" y="2" width="20" height="20" rx="4" fill="#2563EB"/><circle cx="12" cy="12" r="5" fill="#FFFFFF"/></svg>
Metric Value
Original330 bytes
Minified199 bytes
Saved131 bytes (39.7%)

In the output the XML declaration and the comment are gone, the trailing zeros such as 2.000 are shortened to 2, and the extra group is removed.

Tips and Common Mistakes

  • Always check the Preview. Compare the result with the original before using it in production.
  • Keep the viewBox. Responsive scaling depends on it. Make sure it is still in the output.
  • Be careful with Shapes to paths. If you animate or restyle individual shapes with CSS or JavaScript, turn this option off.
  • Watch IDs when you inline several SVGs. Duplicate IDs on one page can make gradients and masks point to the wrong element.
  • Keep the XML declaration for non-UTF-8 files. It is safe to remove for normal inline SVG, but it carries the encoding for other encodings.
  • Use lower precision carefully. 1 or 2 decimals suit icons. Detailed art may need 3 or more.
  • Keep the original file. Optimization removes data you cannot restore.

Common Use Cases

  • Icons and logos: smaller files for websites and apps.
  • Inline SVG in HTML or React: less markup to ship.
  • CSS backgrounds: compact SVG to embed in a stylesheet.
  • Design exports: clean up files from design tools.
  • Illustrations: reduce size while checking quality in the Preview.

Frequently Asked Questions

Will SVG optimization break my image?

SVGO is designed to keep the visual output the same. Some options, such as Shapes to paths, change the internal structure. Always check the Preview before you use the result.

What does Shapes to paths do?

It rewrites shapes like <rect> and <circle> as <path> elements. That is often smaller, but you can no longer adjust the shape with its own attributes, which matters if you animate or restyle it.

What does Precision mean?

Precision is the number of decimal places kept in numbers such as path coordinates and shape attributes. Lower values make smaller files but can slightly change curves. 2 decimals work for most icons.

Is it safe to remove the XML declaration and doctype?

For SVG used inline in HTML, yes. Keep the declaration if your file uses an encoding other than UTF-8.

Should I use Minify or Beautify?

Use Minify SVG for production. Use Beautify to read or edit the file. Beautify formats the SVG with indentation and does not optimize it.

How do I use the minified SVG in HTML, CSS, or React?

Paste it inline in HTML, convert it to a CSS background, or convert it to JSX with the related tools below.

How much smaller will my SVG be?

It depends on the file. The example above saves 39.7%. SVGs exported from design tools, with metadata, comments, and long decimals, usually shrink the most. Original, Minified, and Saved show the exact numbers for your input.

Is my SVG uploaded to a server?

No. SVGO runs in your browser, and your SVG never leaves your device.