SVGO Guide: How to Optimize SVG Files

By Žan Ožbot • Published • Updated • 6 min read

SVGO is the standard tool for optimizing SVG files. It parses the file, removes what browsers do not need, and rewrites the rest more compactly. This guide covers SVGO 4: how to run it, what it changes, and which settings can break a graphic.

Optimize an SVG online

The quickest way is SVGLite, which runs SVGO in your browser. Drop in one file or a batch and download the results. Files stay on your device, and there is nothing to configure.

Run SVGO from the command line

With Node.js installed, no setup is needed:

# One file
npx svgo icon.svg -o icon.min.svg

# Every SVG in a folder, including subfolders
npx svgo -r -f ./icons -o ./icons-min

# Repeat until nothing more can be saved, with 2 decimal places
npx svgo icon.svg --multipass --precision 2 -o icon.min.svg

Without -o, SVGO overwrites the original, so keep the source file in version control.

What SVGO removes

  • Editor data: metadata, comments and namespaces from Illustrator, Inkscape or Sketch
  • Defaults: attributes that repeat what the browser would do anyway
  • Extra precision: coordinates rounded to three decimals by default
  • Verbose paths: absolute commands become relative ones when shorter
  • Redundant structure: empty groups, unused definitions and hidden elements
  • Long colors and IDs: for example, rgb(255, 0, 0) becomes red

How much does it save?

It depends on the source. The six cover images on this blog were exported by a design script and shrank by 49% to 55% with the settings SVGLite uses, with pixel-identical rendering in our test. A house icon that was already hand-tuned did not shrink at all.

See the full size table, which also covers gzip and Brotli.

A config to start from

Save this as svgo.config.mjs in your project root:

export default {
  multipass: true,
  plugins: [
    {
      name: "preset-default",
      params: {
        overrides: {
          // keep IDs that your CSS or JavaScript refers to
          cleanupIds: false,
        },
      },
    },
    // let CSS control the size (keep the viewBox)
    "removeDimensions",
  ],
};

In SVGO 4 the default preset keeps viewBox and title. In version 3 both were removed by default, so older configs that override removeViewBox to false are no longer needed.

Settings that can break an SVG

PluginWhat can go wrongFix
cleanupIdsCSS, JavaScript or links that use the ID stop working; short IDs can clash when several SVGs are inlinedDisable it, or add prefixIds
mergePathsYou can no longer style or animate the shapes separatelyDisable it
collapseGroupsGroups you animate may disappearDisable it
removeHiddenElemsElements you reveal later with CSS are deletedDisable it
removeDescSome descriptions are removed, which can affect accessibilityDisable it for meaningful images
removeViewBoxThe SVG stops scalingDo not enable it

SVGLite uses the default preset, including the first five plugins in this table. Keep the original of any SVG you script or animate.

Add SVGO to a build

A package.json script covers most projects:

{
  "scripts": {
    "svg": "svgo -r -f src/icons"
  }
}

In React, SVGR can run SVGO for you through @svgr/plugin-svgo. In Vite, use a plugin that wraps SVGO if you import SVGs as components.

Check the result

Optimize your SVG files

Drop your SVGs into SVGLite to shrink them in your browser. Nothing is uploaded.

Open the SVG optimizer

Related guides

June 3, 2023 • 10 min read
How to Reduce SVG File Size: 10 Proven Ways
Make SVG files smaller without losing quality. Ten steps covering export settings, path precision, SVGO and gzip, with measured before and after sizes.
June 5, 2025 • 8 min read
SVG vs PNG: What's the Difference and Which Is Better?
SVG stores shapes, PNG stores pixels. Compare scalability, file size, quality, printing and transparency, and see when to use each, with measured sizes.
June 2, 2023 • 5 min read
SVG Compression: Gzip, Brotli and SVGZ Compared
How much do gzip and Brotli shrink an SVG? Measured results for six files, server config for Nginx and Apache, and when SVGZ is worth using.