Guide · Open source
How to use SVGO: install, optimize SVG files and configure it
Updated · written with AI from the project's own documentation and checked against our catalogue data
SVGO (short for SVG Optimizer) is a Node.js library and command-line tool that removes unneeded data from SVG files, such as editor metadata, comments and hidden elements, without changing how the image looks. This guide is for web developers, build-script authors and anyone batch-processing exported SVGs. By the end you will know how to install it, run it on single files and whole folders, and adjust its settings.
Quick start
- 1Install SVGO. Install SVGO globally with npm install -g svgo. You need Node.js and npm, yarn or pnpm available first.
- 2Try it on one file. Run svgo with an input file and -o followed by an output file name to create a smaller copy.
- 3Process a folder. Use svgo -rf with your folder path and -o with an output folder to optimize many files recursively.
- 4Create a config file. Add svgo.config.mjs to your project to set plugins and options such as multipass.
- 5Adjust the default preset. Use the overrides key under preset-default to disable a plugin or change its parameters.
- 6Use the API in a build step. Import optimize from svgo in your script and write result.data to disk.
Install SVGO with npm, yarn or pnpm
SVGO is installed through a package manager. You need Node.js and npm, yarn or pnpm on your computer. The README shows a global install with npm, which makes the svgo command available everywhere.
If you want to use SVGO inside a Node.js project instead, leave out the global flag (-g).
- npm: install globally with the -g flag
- yarn: use yarn global add svgo
- pnpm: use pnpm add -g svgo
npm install -g svgoOptimize single SVG files from the command line
Pass one or more input files, then use -o to name the output files. Each output file goes in the matching position of the list, so the first input becomes the first output.
Run svgo --help to see the other options for advanced usage.
svgo one.svg two.svg -o one.min.svg two.min.svgProcess a whole folder of SVGs recursively
For batch work, use -r (or --recursive) together with -f (or --folder) and point SVGO at a directory. Add -o with an output directory to write the results somewhere else.
This is the usual approach for designers or teams who export many SVGs at once.
svgo -rf path/to/directory_with_svgs -o path/to/output_directoryConfigure SVGO with svgo.config.mjs
SVGO has a plugin architecture. It reads its settings from a file called svgo.config.mjs, or from a file you pick with the --config option. Some other parameters can also be set with command-line options.
The config file can set options such as multipass, datauri and js2svg, and list the plugins to run. Plugins can be enabled by name, or by name with a params object to configure them. The README's example enables preset-default and prefixIds, and sets prefixIds to the prefix 'uwu'.
- multipass: a boolean that controls whether SVGO runs more than one pass
- datauri: 'base64', 'enc' or 'unenc'
- js2svg: indent (number) and pretty (boolean) for output formatting
export default {
multipass: false,
datauri: 'base64',
js2svg: {
indent: 4,
pretty: false,
},
plugins: [
'preset-default',
'prefixIds',
{
name: 'prefixIds',
params: {
prefix: 'uwu',
},
},
],
};Change the default preset
Rather than building a setup from scratch, you can adjust the default preset. Use the overrides key to turn off a default plugin or change its parameters. The README shows cleanupIds being disabled and inlineStyles being given onlyMatchedOnce: false.
The full list of default plugins, in the order they run, is in the Preset Default documentation at svgo.dev.
export default {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
cleanupIds: false,
inlineStyles: {
onlyMatchedOnce: false,
},
},
},
},
],
};Use SVGO in code with the optimize function
If you are writing a script or tool, import optimize from svgo. It takes an SVG string and an options object, and returns a result whose data field holds the optimized SVG string. The README recommends passing a path value.
The loadConfig function can find and load your svgo.config.mjs file, and it also accepts a config file path and a working directory.
import { optimize } from 'svgo';
const result = optimize(svgString, {
path: 'path-to.svg',
multipass: true,
});
const optimizedSvgString = result.data;What people use it for
- Shrinking SVG icons before loading them on a web page
- Cleaning exported SVG files in a build step or npm script
- Batch-processing a folder of exported SVGs from a design tool
- Adding a prefix to IDs with the prefixIds plugin, as in the README example
- Keeping a shared svgo.config.mjs so a team gets the same output
Frequently asked questions
Is SVGO free to use?
Yes. SVGO is released under the MIT license, as stated in the README's license section. You can read the full license text in the project's LICENSE file on GitHub.
How do I install SVGO?
Install it through npm, yarn or pnpm. The README gives the global npm command npm install -g svgo. Leave out the -g flag if you want to use it inside a Node.js project.
Do I need Node.js to use SVGO?
Yes. SVGO is a Node.js library and command-line tool, and installation depends on Node.js and npm, yarn or pnpm. Users who cannot run these will not be able to install it.
Can SVGO process a whole folder at once?
Yes. Use svgo -rf with the folder path and -o with an output directory. The -r flag processes the folder recursively.
Will optimizing an SVG change how it looks?
SVGO removes data that can be taken out without affecting rendering, such as editor metadata, comments and hidden elements. Optimization removes data by design, so editor-specific details may be lost if you need to keep them.
Is there a graphical app for SVGO?
No. The README does not show a visual interface. SVGO is a command-line tool and library, so you run it from a terminal or code.
New agent skills, repos and AI tools — every week
The best new skills and open-source projects, the fastest-growing repos, and one free prompt. Five minutes to read. Unsubscribe anytime.
Our verdict
SVGO suits web developers, build-script authors and teams who batch-process SVGs and are comfortable with Node.js and npm. If you need a graphical app, or must keep every editor-specific detail in your SVG files, pick a different approach.
Install options & downloads