Hunt
Skip to content

SVG Optimizer

Paste an SVG to make it smaller with SVGO, the optimiser most build tools use. It removes editor metadata, comments and unused definitions, shortens path data, numbers and colours, and keeps the viewBox and title. Compare the before and after previews, then copy or download the result.

Runs in your browser

SVG

Paste SVG or press Sample

Optimised

The optimised SVG will appear here

What gets removed

Design tools save more than the drawing. Inkscape, Illustrator, Figma and Sketch add their own namespaces and settings, XML declarations, comments, empty groups, IDs nothing uses and numbers with six or more decimals. None of it affects how the SVG looks in a browser. SVGO's default preset removes it, merges and shortens paths, and writes colours and numbers in their shortest form.

The viewBox and <title> are kept: the viewBox lets the SVG scale, and the title is its accessible name.

How to use the SVG Optimizer

  1. Paste SVG code, or press Sample.
  2. Check the size saved and compare the before and after previews.
  3. Adjust Decimals and the other options if something changed.
  4. Copy the optimised SVG or download it.

Examples

An icon saved by Inkscape

Input
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" width="24px" height="24px" viewBox="0 0 24 24" version="1.1" id="svg8" inkscape:version="1.3 (0e150ed6c4, 2023-07-21)" sodipodi:docname="check.svg">
  <sodipodi:namedview id="namedview1" pagecolor="#ffffff" bordercolor="#666666" inkscape:zoom="22.627417"/>
  <defs id="defs2"/>
  <g inkscape:label="Layer 1" inkscape:groupmode="layer" id="layer1">
    <title id="title1">Done</title>
    <circle style="fill:#22c55e;fill-opacity:1;stroke:none" id="circle1" cx="12.000000" cy="12.000000" r="10.000000"/>
    <path style="fill:none;stroke:#ffffff;stroke-width:2.0000000;stroke-linecap:round;stroke-linejoin:round" d="M 7.0000000,12.500000 L 10.500000,16.000000 L 17.000000,8.5000000" id="path1"/>
  </g>
</svg>
Output
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><title>Done</title><circle cx="12" cy="12" r="10" style="fill:#22c55e;fill-opacity:1;stroke:none"/><path d="m7 12.5 3.5 3.5L17 8.5" style="fill:none;stroke:#fff;stroke-width:2;stroke-linecap:round;stroke-linejoin:round"/></svg>

991 bytes down to 310 (69% smaller): the editor's metadata, IDs, layer group and long decimals are gone; the title and viewBox stay.

Fewer decimals in path data

Input
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M10.12345 20.98765 C 30.55555 40.44444, 60.33333 70.11111, 90.99999 10.00001" fill="none" stroke="black"/></svg>
Output
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path fill="none" stroke="#000" d="M10.1 21C30.6 40.4 60.3 70 91 10"/></svg>

At the default 3 decimals the path is M10.123 20.988C30.556 40.444 60.333 70.11 91 10.

Keeping IDs that CSS refers to

Input
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><defs><linearGradient id="brand-gradient"><stop offset="0" stop-color="#facc15"/><stop offset="1" stop-color="#f97316"/></linearGradient></defs><rect id="badge" width="24" height="24" rx="6" fill="url(#brand-gradient)"/></svg>
Output
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><defs><linearGradient id="brand-gradient"><stop offset="0" stop-color="#facc15"/><stop offset="1" stop-color="#f97316"/></linearGradient></defs><rect id="badge" width="24" height="24" fill="url(#brand-gradient)" rx="6"/></svg>

Without Keep IDs, brand-gradient becomes a and the unused id="badge" is removed, which breaks a stylesheet rule such as #badge:hover.

When to change the options

  • Decimals: 3 is safe for most icons. Lower it for smaller files, but check the preview: small shapes and detailed illustrations can shift visibly at 0 or 1.
  • Keep IDs: turn on when CSS, JavaScript or another SVG refers to elements by ID (#logo-path, <use href="#icon">). Otherwise IDs are shortened or removed.
  • Remove width/height: for icons that should scale with their container in CSS. The viewBox keeps the proportions.
  • Indent output: readable output for code review; the minified version is smaller.

Common errors and how to fix them

A tag that is never closed

SVG is XML, so every element must be closed, either with an end tag or as <g/>. Browsers may still draw a broken SVG inline in HTML, but it fails as a file.

Invalid
<svg><g></svg>
Fixed
<svg><g></g></svg>

The tool reports: This SVG isn't valid XML:

Options

Decimals
Decimal places kept in coordinates and numbers (default 3).
Multipass
Repeat the optimisations until nothing changes. Slightly smaller output; on by default.
Keep IDs
Keep every id attribute as it is, for CSS, scripts and references from other files.
Remove width/height
Drop the fixed size so the SVG scales to its container; the viewBox is kept.
Indent output
Pretty-print the result on several lines.

Limitations

  • Inline style attributes are kept as they are.
  • Embedded raster images (<image href="data:…">) aren't compressed.
  • Scripts and animations are kept, but IDs they use may be renamed unless Keep IDs is on.
  • Inputs up to a few megabytes; very large illustrations can take a few seconds.

Frequently asked questions

Will optimising change how my SVG looks?

Normally not: the default settings only remove what browsers ignore and round numbers to 3 decimals. Compare the previews; if anything shifted, raise Decimals.

Is this the same as running SVGO?

Yes. It runs SVGO 4 with its default preset in your browser, plus the options shown. Use the same settings in svgo.config.js to reproduce the result in a build.

Why are my IDs gone?

SVGO shortens IDs and removes unused ones. Turn on Keep IDs if CSS, JavaScript or other files refer to them.

Is my SVG uploaded?

No. SVGO runs in a Web Worker in your browser, and the previews are drawn as images, so scripts inside the SVG never run.