SVGO

Node.js library and CLI that optimizes SVG files by removing metadata, comments, hidden elements and redundant values, using a configurable plugin system.

install

SVGO (SVG Optimizer) is a Node.js library and command-line application that reduces SVG file size. SVG files exported from vector editors often contain editor metadata, comments, hidden elements, and default or suboptimal values. SVGO uses configurable plugins to remove or simplify this information; review the resulting assets when choosing optimization settings.

On the command line, svgo one.svg two.svg -o one.min.svg two.min.svg processes individual files. svgo -rf path/to/directory_with_svgs -o path/to/output_directory processes a directory recursively using -r/--recursive and -f/--folder. svgo --help lists the advanced options.

Optimization is done by a plugin architecture. A preset-default bundle of built-in plugins is enabled by default. You can disable or override individual plugins' parameters through overrides, enable other built-in plugins such as prefixIds by name, or write custom plugins inline or import them from another JavaScript file. Configuration is read from svgo.config.mjs or from the --config option, and it also covers options like multipass, datauri output (base64, enc, unenc), and js2svg formatting (indent, pretty).

For programmatic use, the optimize function takes an SVG string and a config object and returns the optimized SVG in result.data. loadConfig resolves the svgo.config.mjs file, which is useful for tools built on SVGO. It is aimed at front-end developers, build-tool authors, and anyone who ships SVG assets.

Installation

# via npm
npm install -g svgo
# via yarn
yarn global add svgo
# via pnpm
pnpm add -g svgo

Alternatives & related tools

add a badge to your README

Maintain SVGO? Show that it's featured on trmn. The badge links back to this page.

Featured on trmn
Markdown
[![Featured on trmn](https://www.trmn.sh/badge/svgo.svg)](https://www.trmn.sh/tools/svgo?utm_source=badge)
HTML
<a href="https://www.trmn.sh/tools/svgo?utm_source=badge"><img src="https://www.trmn.sh/badge/svgo.svg" alt="Featured on trmn" height="20"></a>