
Optimizing SVG Icons: What to Strip, What to Keep
The icon build does two jobs: optimization strips editor cruft, normalization makes every icon behave the same — viewBox, currentColor, stroke convention, ids.
TL;DR: The build that turns raw exported SVGs into a shippable icon set does two jobs, and the second matters more than the first. Optimization removes editor cruft and shrinks files; normalization makes every icon behave the same — a guaranteed viewBox, currentColor fills, a consistent stroke convention, collision-free ids. This guide covers what to strip, which optimizer steps are destructive to small icons, the normalization the optimizer's default preset will not do for you, and how to make the whole thing a checked build step.
Why raw exports are not shippable
An SVG straight out of a design tool is not a bad file — it is an editor's working file, and it carries everything an editor needs. That means metadata blocks, XML comments, editor-specific namespaces, redundant nested groups, absolute coordinates from wherever the artboard happened to sit, hardcoded fill colors, and internal ids that were unique only within that one export. None of it is wrong. All of it is wrong to ship.
The obvious problem is size: that cruft inflates every icon, and across a set of hundreds it adds up. The less obvious and more damaging problem is inconsistency. One export has a viewBox and another does not, so they scale differently. One uses a hardcoded black fill and another uses none, so one themes and the other does not. One nests its paths three groups deep and another is flat, so styling hooks land in different places. The pipeline's real job is uniformity as much as compression: every icon should size, color, and reference the same way, so a consumer can treat the set as one predictable thing.
What SVGO does, and the destructive plugins to watch
SVGO, a Node.js library and command-line application for optimizing SVG files, is a pipeline of plugins that remove, merge, convert, round, or otherwise rewrite parts of the file. The safe wins are uncontroversial: strip metadata, comments, and editor namespaces; collapse useless groups; round path coordinates to a sensible precision. Run just those and an exported icon sheds that editor cruft with no visible change; measure the byte saving on your own set rather than assuming a figure.
Two cautions matter. First, SVGO's default plugin set has changed across major versions, so a configuration copied from a blog post may enable or disable different plugins than you expect (verify against the version you actually run; as of Nov 2026, svgo.dev). A configuration worth trusting is one whose plugins you understand, not one you inherited. Second, some plugins are destructive to small icons specifically. Aggressive path merging can weld shapes that were meant to stay separate. Removing the viewBox (SVGO's removeViewBox plugin drops it where it matches the width and height, saving a few bytes) breaks predictable scaling. It has not been part of SVGO's default preset since v4.0.0 (June 2025), but it was on by default in SVGO 2 and 3, so keep it out of an icon set's configuration and check which version your build actually runs (as of Nov 2026, svgo.dev). And precision rounding that is fine for an icon drawn on a 512-unit viewBox can visibly distort one drawn on a 16-unit viewBox, shifting a stroke off its intended line. Configure these deliberately; do not accept the defaults blindly on a set that renders small.
Normalization beyond the optimizer's defaults
Optimization makes icons smaller and cleaner. Normalization makes them uniform, and SVGO's default preset does not do it: some steps have opt-in plugins (prefixIds for ids, the currentColor option of convertColors, removeDimensions, which removes the root width and height and adds a viewBox if one is missing), but the conventions themselves are yours to define and enforce. Three normalizations are worth enforcing in the build, alongside the id namespacing covered in the next section.
Guarantee a viewBox. Every icon needs a coordinate box, and ideally the same one across the set, so that "render at size 20" produces the same visual result for every icon. Without a consistent box, the same CSS size yields different apparent sizes because the drawings sit differently inside their coordinate space. The build should ensure a viewBox is present and the drawing is consistently positioned within it.
Convert fills to currentColor. A hardcoded fill is an icon that ignores its context. Rewriting single-color fills to currentColor is what lets an icon inherit the color of the text or button around it, and it is the precondition for theming to work uniformly. For multi-color icons, the build should apply a documented convention — a CSS custom property per accent, say — rather than leaving hardcoded values scattered through the set.
Standardize the fill-versus-stroke convention. An icon set that mixes filled and stroked drawings, or that varies where stroke width is declared, behaves unevenly when consumers try to size or recolor it. Deciding on one convention and enforcing it in the build is what keeps stroke-width and color behaving the same everywhere.
The id-collision problem
There is a specific failure mode that bites hardest with inline and inlined-sprite delivery, and it surprises people because each icon works fine in isolation. Gradients, clip paths, masks, and filters inside an SVG are referenced by id. Those ids came from the design tool, and across a set, exports collide — two icons both define #gradient-1. Render both on the same page and one definition overrides the other, so an icon suddenly renders with the wrong gradient or loses its clip entirely.
The fix belongs in the build: prefix or hash every internal id per icon so no two collide, or, where practical, avoid id-dependent features altogether for icons that do not truly need them. This is invisible until two icons happen to share a page, which is exactly why it should be handled once in the pipeline rather than debugged later as a mysterious rendering glitch. An icon system that inlines its icons and does not namespace ids is carrying a latent collision waiting for the wrong two icons to meet.
Automating the source-to-output step
All of this should be a build, not a ritual someone remembers to perform. The shape is simple: watch a source folder of drawn SVGs, run optimize and normalize on each, and emit whatever the delivery method needs — a sprite, a set of components, or individual modules. The effect on a single icon is legible at a glance:
before <svg xmlns="..." data-name="Layer 1" viewBox omitted>
<g id="group-1"><path fill="#111827" d="..."/></g>
</svg>
after <svg viewBox="0 0 24 24">
<path fill="currentColor" d="..."/>
</svg>That is shape, not a configuration to copy — a pasted config goes stale as the optimizer version drifts, which is the reason to show the reasoning instead. The value of making it an automated, checked build step is that an unoptimized or non-conforming icon cannot land unnoticed. When adding an icon means dropping a source file and letting the pipeline produce the artifact, the set stays uniform by construction. When it means a person remembering to run a tool with the right flags, the set drifts one hurried commit at a time — which is precisely the entropy an icon system exists to prevent.