# SVGO

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

Stars: 22.8k · Language: JavaScript · License: MIT · Categories: Dev Tools

- Repository: https://github.com/svg/svgo
- Website: https://svgo.dev/
- Page: https://www.trmn.sh/tools/svgo

## Install

- npm: `npm install -g svgo`
- yarn: `yarn global add svgo`
- pnpm: `pnpm add -g svgo`

## Overview

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

```bash
# via npm
npm install -g svgo
```

```bash
# via yarn
yarn global add svgo
```

```bash
# via pnpm
pnpm add -g svgo
```

## Alternatives

- [semantic-release](https://www.trmn.sh/tools/semantic-release.md): Automates releases from CI: derives the next semver version from commit messages, generates release notes, tags Git, and publishes packages via plugins. (JavaScript, 24.2k stars)
- [AVA](https://www.trmn.sh/tools/ava.md): Node.js test runner that runs test files concurrently in isolated processes, with diff-based assertion output, TypeScript definitions, and watch mode. (JavaScript, 20.8k stars)
- [terminalizer](https://www.trmn.sh/tools/terminalizer.md): Terminal session recorder that generates animated GIF images from command-line sessions (JavaScript, 16.2k stars)
- [release-it](https://www.trmn.sh/tools/release-it.md): Generic CLI for automating releases: version bumps, git commit/tag/push, changelogs, GitHub/GitLab releases, and npm publishing, with hooks and plugins. (JavaScript, 9.1k stars)
- [np](https://www.trmn.sh/tools/np.md): Interactive release tool for npm packages that checks the working tree, runs tests, bumps versions, creates tags, publishes, and pushes to Git. (JavaScript, 7.7k stars)

---

Canonical: https://www.trmn.sh/tools/svgo
