You export a simple logo from a design tool and the SVG is 18 KB. The same shape drawn by hand would fit in a few hundred bytes. Multiply that by an icon set of forty files, inline them into every page, and the bloat becomes a real cost: larger HTML, slower first render, and code reviews full of unreadable noise.
This guide explains where the extra bytes in an SVG come from, which optimisations are safe and which can change how a graphic looks or behaves, and how to optimise files step by step while checking the result visually.
Where the extra bytes come from
An SVG exported from Inkscape, Illustrator, Sketch or Figma typically contains much more than the drawing itself:
- Comments such as
<!-- Generator: … -->. - Metadata: an
<metadata>block with RDF descriptions, licence information or document titles. - Editor data: attributes and elements in the
inkscape:,sodipodi:or Illustrator namespaces that only the editor uses, such as layer names, guide positions and zoom level. - Excess precision: coordinates like
12.000000381469727where12would look identical. - Whitespace and indentation that makes the file readable but adds bytes.
- Empty groups left over from deleted layers.
- Verbose CSS in
<style>blocks.
Here is a small example before optimisation:
<!-- Generator: Example Editor -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<metadata>Badge icon</metadata>
<g></g>
<circle cx="12.00004" cy="11.99998" r="10.000001" fill="#0ea5e9"/>
</svg>
And after:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="12" cy="12" r="10" fill="#0ea5e9"/></svg>
Both render the same circle.
How coordinate rounding works
Rounding is usually the single biggest saving, and the one that needs the most thought. Whether rounding is visible depends on the size of the coordinate system relative to the display size.
In a viewBox="0 0 24 24" icon shown at 24 pixels, one unit equals one pixel. Rounding to 2 decimal places moves points by at most 0.005 pixels, which is invisible. Rounding to 0 decimal places can move points by half a pixel, which may soften curves or misalign shapes.
In a viewBox="0 0 2400 2400" illustration shown at 300 pixels, each unit is only 0.125 pixels, so even 0 or 1 decimal place is usually safe.
A good rule: start with 2 decimal places, compare before and after, and only go lower if the file is large and the result still looks identical when zoomed in.
Optimise an SVG with our tool
Our SVG Optimizer cleans SVG markup in your browser and shows the before and after images side by side.
- Open the SVG Optimizer. A sample badge exported with Inkscape data is loaded.
- Paste your markup into Original SVG, or click Open .svg file.
- Set Decimal places. 2 (recommended) is the default; choose Don't round to leave numbers alone or 0 to 5 for a different precision. Rounding applies to paths, shapes, transforms and inline styles.
- Choose what to remove with the switches: Remove comments, Remove
<metadata>, Remove editor data (Inkscape, Sodipodi, Illustrator, Sketch), Collapse whitespace, Minify<style>CSS and Remove empty groups are on by default. Remove<title>/<desc>is off, because those elements help accessibility. - Check the Original, Optimized and Saved tiles for the size difference.
- Compare the Before and After previews. If anything looks different, raise the decimal places or turn off the option you suspect.
- Click Copy or Download .svg to save the optimised file.
Safe versus risky optimisations
| Optimisation | Risk | Notes |
|---|---|---|
| Remove comments | None | Unless a licence notice must stay in the file |
| Remove metadata and editor data | Very low | You lose layer names if you reopen it in the editor |
| Collapse whitespace | None for shapes | Can change spacing in <text> with meaningful spaces |
| Round to 2 decimals | Very low for icons | Check detailed illustrations |
| Round to 0 decimals | Moderate | Can distort small curves |
| Remove empty groups | Low | Scripts or CSS may target an empty group by ID |
| Remove title and desc | Accessibility cost | Screen readers use them for meaningful images |
Keep your editable original. An optimised SVG is a delivery file, like a compiled asset; always go back to the source file when you need to change the design.
Other ways to optimise SVGs
SVGO on the command line
SVGO is the standard open-source optimiser and is used by many build tools. Install it with Node.js and run it over a folder:
npx svgo -f ./icons -o ./icons-optimized
It has more transformations than a browser tool, such as merging paths and converting shapes to shorter path data. It is the best choice for build pipelines and large icon sets. Its more aggressive plugins can occasionally remove things you need (for example IDs referenced by CSS), so review its configuration.
Export settings in your design tool
Most design tools have export options such as "minify", "remove metadata" or decimal precision. Setting these once saves work on every export. They rarely remove everything, so a final pass through an optimiser still helps.
Server compression
Gzip and Brotli compression on your web server shrink SVG files further in transit because XML compresses very well. This works alongside optimisation, not instead of it: a smaller source still compresses to a smaller result, and inline SVGs benefit from being lean in the HTML itself.
Troubleshooting
Parts of the graphic disappeared
The removed element was probably referenced by ID from CSS, a <use> element or a script. Turn off Remove empty groups, re-run, and compare.
Curves look slightly wobbly
The rounding was too aggressive for the size of the coordinate system. Increase Decimal places by one and check again.
The text spacing changed
Collapsing whitespace can affect <text> elements. Turn off Collapse whitespace for files that contain live text, or convert the text to paths in your editor.
It looks right but is still large
Embedded bitmap images (<image href="data:image/png;base64,…">) are the usual culprit. An optimiser cannot shrink them much. Compress the image separately with the Image Compressor, or ask whether the graphic should be a PNG or WebP in the first place. You can inspect the size and viewBox of any file in the SVG Viewer, and export a raster copy with SVG to PNG.
Frequently asked questions
Does optimising an SVG reduce its quality?
Removing comments, metadata and whitespace has no visual effect. Rounding coordinates can, but at 2 decimal places the change is invisible for typical icons and logos.
How much smaller will my SVG get?
It depends on how it was created. Files exported from design tools with metadata often shrink a lot, while hand-written or already optimised files change very little. The Saved tile shows the exact result.
Should I remove the title and desc elements?
Keep them for meaningful images that screen reader users need to understand. For purely decorative icons, you can remove them and hide the SVG from assistive technology with aria-hidden="true".
Can I still edit an optimised SVG in Inkscape or Illustrator?
Yes, it still opens, but layer names and editor settings are gone. Keep the original file for editing and use the optimised one for your website.
Is my SVG uploaded to a server?
No. The optimisation runs in your browser, and the file never leaves your device.