SVG Minifier
Optimize SVG files with SVGO: remove metadata, collapse groups, and control number precision
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
- Paste your SVG code into the input box, or click Example to load a sample.
- Choose your options. The table below explains each checkbox, and Precision controls decimal places.
- Click Minify SVG.
- Check the Preview. Make sure the optimized image still looks right.
- 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 comments | Deletes XML comments such as <!-- Created with a design tool --> | Low risk |
| Collapse groups | Merges <g> groups that add nothing | Keep groups you target with CSS or JavaScript |
| Remove empty attrs | Deletes attributes with empty values | Low risk |
| Remove empty containers | Deletes elements such as empty <g> or <defs> | Low risk |
| Shapes to paths | Converts <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 attributes | Puts attributes in a consistent order | Helps gzip compress the file better |
| Remove unused namespaces | Deletes namespace declarations nothing uses | Common in files from design tools |
| Remove XML declaration | Deletes <?xml ... ?> | Fine for inline SVG |
| Remove doctype | Deletes <!DOCTYPE ...> | Fine for inline SVG |
| Clean up attribute values | Tidies whitespace and formatting inside attribute values | Low risk |
| Precision | Rounds numbers in path data and numeric attributes to 1 to 5 decimal places | Lower 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 decimal | 12.3 | Small icons, smallest files |
| 2 decimals | 12.35 | Most icons and logos |
| 3 decimals | 12.346 | Detailed illustrations |
| 4 decimals | 12.3456 | Large or precise artwork |
| 5 decimals | 12.3456 | Maps 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 |
|---|---|
| Original | 330 bytes |
| Minified | 199 bytes |
| Saved | 131 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.
Related Tools
SVG Viewer
Preview SVG files in the browser
SVG to PNG
Convert SVG to a PNG image
SVG to JSX / React
Convert SVG markup to JSX
SVG to CSS Background
Embed SVG in a CSS background
Image Optimizer
Compress raster images
Code Minifier
Minify many languages in one tool