Writing a Custom SVGO Plugin
A custom SVGO plugin lets a project enforce cleanup rules, like stripping proprietary attributes, that built-in plugins don't cover.
Drop your image here
Supports PNG, JPG, BMP, WEBP up to 5MB
The Visitor Pattern for Custom Plugins
SVGO's plugin API uses a visitor pattern where a custom plugin defines an element visitor function that receives each node in the SVG's parsed tree, letting the plugin inspect or mutate attributes, remove nodes, or collect information across the whole document during a single optimization pass.
- A visitor function receives each node in the SVG's parsed tree in turn
- The plugin can inspect, mutate, or remove nodes during the visit
- Runs as part of a single optimization pass alongside built-in plugins
Practical Custom Plugin Examples
A common custom plugin strips proprietary editor metadata attributes left behind by design tools that built-in plugins don't recognize, while another might enforce a project's naming convention on retained IDs, or inject a consistent data attribute onto every path element for downstream JavaScript hooks.
- Custom plugins can strip proprietary editor metadata built-in plugins miss
- Can enforce a project's specific naming convention on any retained IDs
- Can inject consistent data attributes onto elements for JavaScript hooks
Frequently Asked Questions
Do custom SVGO plugins run alongside built-in plugins?
Yes, a custom plugin is simply added to the plugins array in the config file and runs in the same optimization pass alongside any built-in plugins listed.
What's a typical reason to write a custom SVGO plugin?
Stripping proprietary metadata attributes left by a specific design tool that no built-in SVGO plugin recognizes is one of the most common reasons to write one.
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