Batch Optimizing SVG Files via CLI
SVGO's command-line interface can recursively optimize an entire folder of SVG files in one command, ideal for large icon sets.
Drop your image here
Supports PNG, JPG, BMP, WEBP up to 5MB
Running SVGO Across a Whole Folder
Running svgo -f ./icons -o ./icons-optimized (or the equivalent in-place flag) processes every SVG file within a folder in one command, applying the same optimization passes — metadata removal, path precision reduction, redundant group collapsing — consistently across an entire icon set rather than optimizing files one at a time by hand.
- One command processes every SVG file within a specified folder
- Applies consistent optimization passes across an entire icon set at once
- Avoids the tedium and inconsistency of optimizing files one at a time manually
Customizing Batch Optimization with a Config File
For a project needing specific optimization rules (like preserving certain IDs used by JavaScript, or a particular precision setting), an svgo.config.js file placed in the project root lets the CLI apply the same customized rule set consistently across every file in a batch run, rather than passing the same flags manually each time.
- A config file lets you preserve specific IDs or set custom precision rules
- Config-driven rules apply consistently across every file in a batch run
- Avoids manually re-specifying the same command-line flags every time
Frequently Asked Questions
Will batch optimization ever break an SVG that relies on specific IDs?
It can, if default settings strip an ID a script depends on — configuring SVGO to preserve specific IDs (via the cleanupIDs plugin settings) in a config file avoids this for icon sets with JavaScript-dependent elements.
Can batch SVG optimization be automated as part of a build process?
Yes, running the SVGO CLI as a build script step or via a bundler plugin automates optimization so it happens consistently on every build without needing to be run manually.
Related guides
Ready to Convert Your Image to SVG?
Free online converter — no sign-up, no watermarks, results in under 3 seconds.
Try It Free — Convert Image to SVG