SVG Optimizer

SVGs exported from Illustrator, Figma or Inkscape often include editor metadata, comments and long decimals. Paste the code or open a file to strip them and see how many bytes you save.

Before–
After–
Saved–

Left: original · Right: optimized

SVG Optimization: How to Shrink SVG Files Without Breaking Them

SVG is the best format for logos, icons and simple illustrations on the web: sharp at any size and usually tiny. But SVGs exported straight from design tools are often several times larger than necessary. They’re full of editor metadata, overly precise numbers and structure that only matters inside the editor. Cleaning them up is quick and usually cuts file size by a third or more.

Bloated SVG export with editor metadata compared with optimized clean SVG code

What’s inside a typical exported SVG

Open an SVG from Illustrator, Inkscape, Sketch or Figma in a text editor and you’ll often find:

  • an XML declaration (<?xml version="1.0" encoding="UTF-8"?>) and sometimes a DOCTYPE,
  • a comment such as “Generator: …”,
  • a <metadata> block, sometimes with RDF licensing information,
  • editor namespaces and attributes like inkscape:label, sodipodi:namedview or sketch:type,
  • <title> and <desc> elements with layer names,
  • IDs on nearly every element (“Layer_1”, “Rectangle-Copy-3”),
  • empty or redundant groups (<g> wrappers with no attributes),
  • coordinates with six or more decimal places: cx="60.0000032",
  • default attribute values that don’t change anything.

Browsers ignore most of this, but they still have to download and parse it.

Safe optimizations

OptimizationTypical savingRisk
Remove XML declaration, comments, metadataSmall to mediumNone for inline/web use
Remove editor namespaces and attributesMedium (large for Inkscape files)None in browsers
Round coordinates to 1–3 decimalsLarge on complex pathsLow at sensible precision
Remove unused IDsSmall to mediumLow, if references are checked
Collapse empty groupsSmallLow
Collapse whitespaceSmall to mediumLow (careful with <text>)

The SVG optimizer above applies these safely by parsing the SVG structure rather than doing blind text replacement, and shows the original and optimized versions side by side so you can confirm nothing changed.

Optimizations that can break things

  • Too little precision. Rounding to zero decimals on a small 24×24 icon can visibly distort curves. Use 1–2 decimals for icons and 2–3 for detailed illustrations and maps.
  • Removing IDs that are referenced. Gradients, clip paths, masks, filters and <use> elements refer to other elements by ID. Remove only IDs that nothing references.
  • Removing <title>. For SVGs used as meaningful standalone images, the title can serve as the accessible name. Keep it, or provide aria-label or alt text in HTML.
  • Removing viewBox. Some tools offer this, but without a viewBox the SVG can’t scale responsively. Keep it.
  • Merging paths and converting shapes to paths. These can save bytes but make the file harder to edit and animate. Fine for final icons, not for files you’ll keep working on.

How much can you save?

Results vary a lot by source:

SourceTypical reduction
Inkscape (Inkscape SVG format)40–70%
Illustrator exports20–50%
Figma exports10–40% (Figma output is already fairly clean)
Hand-written or icon-library SVGs0–15%

On a simple icon that saves a few hundred bytes; on a detailed illustration with long path data, it can save tens of kilobytes.

Optimization versus compression

Like CSS and HTML, SVG is text, so servers usually compress it with gzip or Brotli during transfer. Compression handles repetitive markup well, so the network saving from optimization is smaller than the raw file-size saving. Optimization still helps: rounding numbers removes information compression can’t, and smaller files parse faster. It’s the same relationship we describe in our CSS minification guide.

Inline SVG versus SVG files

MethodProsCons
Inline <svg> in HTMLNo request; style with CSS (currentColor), animate partsRepeated on every page; not cached separately
<img src="icon.svg">Cached; simpleCan’t style internals with page CSS
CSS background (data URI or file)Good for decorative iconsNot accessible content; limited styling
SVG sprite with <use>One cached file for many iconsSlightly more setup

Optimize before inlining: every byte of inline SVG is repeated in every HTML page that contains it.

Making icons themeable

A simple step after optimizing: replace hard-coded colors in icon SVGs with currentColor:

<path d="…" fill="currentColor"/>

The icon then takes the text color of its parent, so it adapts to hover states, dark mode and different contexts without separate files.

Accessibility reminders

  • Decorative inline SVGs: add aria-hidden="true" so screen readers skip them.
  • Meaningful SVGs used as <img>: provide alt text.
  • Meaningful inline SVGs: add role="img" and an accessible name, for example with <title> or aria-label.

For build pipelines

For ongoing projects, automate optimization with SVGO, the standard open-source SVG optimizer, which is also built into many bundlers and icon tools. It has a large set of plugins, including path merging and transform flattening, with safe defaults. Use an online optimizer for one-off files, quick checks or learning what an optimizer changes.