⚡ Vector Optimization

SVG Code Optimizer & Minifier

Strip comments, the XML prolog and DOCTYPE, <metadata> blocks, Inkscape and Sodipodi editor data, empty groups and whitespace between tags from SVG markup.

Clean Minified SVG

Why exported SVG files carry extra weight

SVG is XML, so an icon is a text document describing shapes. Design tools write that document for humans and for their own round-tripping: indented markup, comments naming layers, editor-specific namespaces, metadata blocks, unused gradients and coordinates with six or more decimal places.

None of that changes what a browser draws. On a large illustration the overhead can exceed the drawing itself, and when the same icon is inlined into every page of a site, the extra bytes are paid on every request.

What a text-level clean-up achieves

This optimizer parses your markup with the browser's XML parser, so malformed SVG is reported instead of silently mangled. It removes comments, the XML prolog and DOCTYPE, metadata elements, Inkscape and Sodipodi elements and attributes, namespace declarations nothing uses any more, empty defs and g elements, and whitespace-only text between tags, then serialises the tree back to XML. Whitespace inside text, tspan, style, title and desc is kept. Processing happens as you type in the page.

Worked example: the sample shown in the editor is 228 characters, spread over four lines with indentation and a comment line. After optimisation it is 193 characters on a single line, a saving of 35 characters or about 15 percent. On hand-written or lightly edited SVG, that is most of the available saving; on raw exports from design tools, much of the weight lives elsewhere.

Deeper optimisations worth knowing

Full optimisers such as SVGO parse the SVG and apply structural rewrites. Knowing what they do helps you decide whether a quick clean-up is enough or whether a file deserves a proper build step.

  • Rounding coordinates: reducing path data from 6 decimal places to 1 or 2 often shrinks a file by a third with no visible change at normal sizes.
  • Path rewriting: converting absolute commands to relative ones and dropping redundant separators.
  • Removing editor data: Inkscape and Illustrator namespaces, sodipodi attributes and metadata elements.
  • Collapsing groups and merging transforms into path coordinates.
  • Removing unused defs such as gradients and clip paths no layer references.
  • Shortening colours, for example #ffffff to #fff.

Rules that keep an SVG working after optimisation

Keep the viewBox attribute. It defines the internal coordinate system and is what lets the icon scale with CSS. Some optimisers remove width and height and keep viewBox, which is fine; removing viewBox and keeping width and height breaks responsive scaling.

Watch for id collisions when several inline SVGs share a page. Two icons that both define a gradient with id a will fight over it, and one icon renders with the other's colours. Give ids a unique prefix per icon.

Do not strip title elements or role and aria attributes from meaningful graphics. They are how screen readers describe the image. Decorative icons, like the sample, can use aria-hidden instead.

Remember that the server compresses text. Whitespace and repeated tag names compress very well with gzip or Brotli, so the transfer saving from minifying is smaller than the raw character saving. Coordinate precision, by contrast, survives compression and is usually the bigger win.

SVG Code Optimizer: frequently asked questions

Does minifying an SVG change how it looks?

Removing comments, editor metadata, empty groups and whitespace between tags does not change rendering, and whitespace inside text elements is left alone. Changes in appearance come from deeper optimisations such as aggressive coordinate rounding, which can shift small details on icons drawn at tiny sizes.

Should I inline SVG or use it as an img source?

Inline SVG can be styled with CSS, for example changing fill on hover, and avoids a request. An img tag keeps the HTML clean and lets the browser cache the file across pages. Inline for small interactive icons; use files for large illustrations.

Why does my optimised SVG show the wrong colours next to another icon?

Two inline SVGs on the same page probably share an id for a gradient, mask or clip path. Ids are global to the whole HTML document, so rename them uniquely in each icon.

Is SVG always smaller than PNG?

For logos, icons and flat illustrations, usually yes, and it stays sharp at any size. For photos or highly detailed artwork with thousands of paths, a PNG or WebP can be far smaller.

All image & media suite