To optimize an SVG, strip the editor metadata, run SVGO with multipass and a precision of 2 or 3, keep the viewBox, render-check the result, and serve the file with gzip or Brotli. On three real files tested for this guide, SVGO 4.1.0 cut 2 to 25 percent; Brotli compression then cut the result by a further 44 to 85 percent.
Last checked: November 20, 2026, by running SVGO 4.1.0 (the npm release) on Node.js 22.23.5 and rendering every output in Chromium 157 through Playwright.
| Key fact | Value | Source |
|---|---|---|
| Current SVGO release tested | 4.1.0 | npm package, installed November 20, 2026 |
| Does SVGO 4's default preset remove the viewBox? | No: removeViewBox and removeTitle are not in preset-default (SVGO 3.3.5 included both) | preset-default.js in the svgo 4.1.0 and 3.3.5 packages |
| Default number precision | 3 decimals (convertPathData floatPrecision default) | convertPathData.js in svgo 4.1.0 |
| Comments kept by default | Comments that start with "!" (license notices) | removeComments.js, default pattern /^!/ |
| Default id handling | cleanupIds renames ids to a, b, c | Our test output, November 20, 2026 |
| Biggest win on an already clean file | gzip or Brotli on the server, not SVGO | Our test table below |
The Five Steps
- Remove editor metadata. XML declarations, export comments, generator tags, layer names, empty groups and "Created with" descriptions. None of it renders, and SVGO's default preset removes it.
- Run SVGO with multipass.
npx svgo@4 icon.svg -o icon.min.svg --multipasscollapses groups, merges paths, moves repeated attributes up and rewrites path data in shorter commands. Run it on copies; keep the editor master. - Set precision on purpose. The default of 3 decimals was visually lossless on every file we tested. Precision 1 changed edge pixels on a 24 pixel icon; precision 0 erased a semi-transparent panel from an illustration (details below). Use 2 or 3 unless you render-check.
- Keep the viewBox. SVGO 4 no longer removes it by default, but SVGO 3's default preset did (we checked 3.3.5, which also removed the title), and old configs copied into build pipelines still do. Without it the file stops scaling.
- Compress on the server. SVG is text. Serving it with Brotli or gzip saved more bytes than SVGO on every file in our test. Check the response header with
curl -sI -H "Accept-Encoding: br" https://your-site/icon.svgand look for content-encoding: br.
Then render the file small, at layout size and large before shipping it. The rest of this guide explains where SVG weight sits, what never to remove, and how to deliver icons.
Test: SVGO 4.1.0 on Three Real Files
We ran SVGO through its Node API on three real files, with multipass on and floatPrecision set to 3 (the default), 2, 1 and 0. Each output was rendered in Chromium against the original, and we counted pixels whose color moved by more than 32 of 255 levels. The script and files were run on November 20, 2026.
The files: the Font Awesome Free 7.3.1 "download" icon (solid set, a publisher-optimized icon on a 448 by 512 grid), the Spain flag from flag-icons 7.6.0 (a detailed coat of arms, already rounded to 1 decimal by its publisher), and a hand-written 800 by 600 illustration from this site's own asset images (indented markup, a gradient, a grid pattern and semi-transparent panels).
| File | Original | After SVGO (precision 3) | Saved by SVGO | Original + Brotli | SVGO + Brotli | SVGO + gzip |
|---|---|---|---|---|---|---|
| Font Awesome download icon | 735 B | 712 B | 3.1% | 388 B | 401 B | 430 B |
| flag-icons Spain flag | 80,958 B | 79,311 B | 2.0% | 12,185 B | 12,160 B | 14,675 B |
| Lucky Graphics illustration | 3,747 B | 2,819 B | 24.8% | 979 B | 821 B | 982 B |
Brotli was run at quality 11 and gzip at level 9 with Node's zlib module.
Three things stand out. Files a publisher has already optimized gain almost nothing from SVGO: 2 to 3 percent. Hand-written or editor files with indentation and long ids gain much more; the illustration lost a quarter of its bytes, mostly whitespace, long ids and repeated style attributes. And compression is the bigger lever everywhere: the flag went from 80,958 bytes to 12,160 on the wire. On the tiny icon, the SVGO output compressed slightly worse with Brotli than the original (401 bytes against 388), because SVGO's shorter path syntax leaves less repetition for the compressor to find. On an icon that small, the difference is noise.
What precision did to the render
| File and render size | Precision 3 | Precision 2 | Precision 1 | Precision 0 | Bytes at precision 0 |
|---|---|---|---|---|---|
| Font Awesome icon at 24 px | 0.00% | 0.35% | 3.47% | 1.74% | 583 B |
| Font Awesome icon at 96 px | 0.00% | 0.02% | 0.15% | 0.47% | 583 B |
| Spain flag at 64 by 48 px | 0.00% | 0.00% | 0.00% | 0.46% | 29,966 B |
| Spain flag at 640 by 480 px | 0.00% | 0.00% | 0.00% | 2.80% | 29,966 B |
| Illustration at 200 by 150 px | 0.00% | 0.00% | 0.00% | 20.47% | 2,266 B |
| Illustration at 800 by 600 px | 0.00% | 0.00% | 0.00% | 20.07% | 2,266 B |
Share of pixels that changed visibly against the original render.
Precision 0 looks tempting on the flag, cutting it from 79,311 bytes to 29,966, but it moves curves in the coat of arms at full size. On the illustration it did something worse than moving curves: precision rounds every number, not only path coordinates, so a fill-opacity of 0.14 became 0 and SVGO then removed the fill as invisible, and a 0.08 stroke-opacity on the grid pattern became 0 too. A fifth of the picture changed. That is the failure a byte count never shows, and why the render check in Step 7 of the safe pass below is not optional.
Precision 1 changed 3.47 percent of the icon's pixels at 24 pixels but only 0.15 percent at 96, because at small sizes a shifted edge lands on a different pixel. An icon must be checked at the smallest size it ships, not only at the size it was drawn.
Where SVG Weight Actually Sits
An SVG is XML text, so every byte is visible and accountable. In an unedited editor export, the weight usually divides like this.
| Source of weight | What it looks like | Safe to remove? |
|---|---|---|
| Export metadata | XML declaration, comments, editor tags, generator names | Yes, always |
| Titles and descriptions for the editor | Title and desc elements naming layers and export settings | Usually; keep or move a title when the file is used as a meaningful image, for accessibility |
| Group scaffolding | Nested g elements with ids and data-name attributes, no styling of their own | Yes, when the group carries no transform, opacity, or class that CSS or script uses |
| Decimal precision | Coordinates like 12.5000 and 18.2500 in path data | Round to what the grid needs; test after rounding |
| Repeated attributes | The same fill, stroke, and style repeated on every path | Move shared values to the root or a parent group |
| Split paths | One shape exported as many path elements, one per pen segment or layer | Merge paths that share fill and style |
| Embedded raster images | A base64 image element inside the SVG, from a placed photo or texture | Not an optimization problem; the file is a photo in a wrapper and belongs in a raster format |
| Unused defs | Gradients, patterns, and symbols defined but never referenced | Yes, after confirming nothing references them, including from CSS |
Two rows deserve emphasis. The embedded raster is the silent failure in many illustration files: an SVG that weighs 400 KB is often a JPEG wearing an SVG coat, and no amount of path cleanup touches it. Open the file, search for an image element with a data URI, and re-export the artwork as true vector or ship the photo as WebP or AVIF instead. If no vector master exists, tracing the bitmap into paths is the free route for flat logos and line art. The unused defs row cuts the other way: a gradient that looks unused inside the file may be referenced by a class in your stylesheet, so check before deleting.
The Worked Example: One Icon, 819 Bytes to 200
This example was drawn and measured for this guide. The icon is a download arrow above a tray, the kind of glyph every interface needs, exported the way design tools export when nobody changes the settings: an XML declaration, an export comment, a title and description, two named groups with ids and data-name attributes, four-decimal coordinates, and the same fill repeated on both paths.
The verbose export measures 819 bytes. After the safe pass described below, the same drawing is one svg element with a viewBox, one fill set to currentColor, and one merged path with rounded coordinates:
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true"><path d="M11 3h2v9.5h3.5L12 18.25 7.5 12.5H11zM4 15h2v4h12v-4h2v6H4z"/></svg>
That file measures 200 bytes, a 75.6 percent reduction, and it renders identically at every size an interface will show. Nothing about the drawing changed. The arrow and tray are the same shapes with the same proportions; the coordinates lost decimals that a 24 unit grid never needed, and the tray path moved into the same path element as the arrow because both shapes share one fill.
Three lessons generalize from the example. First, the saving came from structure, not from redrawing: metadata, grouping, precision, and repetition. Second, the merged path uses relative commands and shorthand where the editor wrote absolute coordinates out in full, which is why hand-optimizers and tools like SVGO earn their keep on real files with hundreds of points. Third, 200 bytes is not the floor for this icon, and chasing the floor would be a mistake. Squeezing the last decimals and path commands out saves almost nothing and makes the file unreadable the next time a designer needs to adjust the arrow by hand. Optimize to clean, not to minimal.
On one icon, 619 saved bytes is nothing. The arithmetic changes with a real icon system. A product interface using sixty icons from an unedited export pays the scaffolding cost sixty times. How much a pass saves depends on how clean the exports were: in our SVGO test above it ranged from 2 percent on publisher-optimized files to 25 percent on a hand-written illustration, and an unedited editor export like this example can lose far more. Measure your own set the same way: weigh the folder before, run the pass, weigh it after, and keep the before and after numbers with the project. Your measured numbers, on your files, are the only statistics in this guide worth quoting to a client.
The Safe Pass, Step by Step
Run these steps in order. Each one is reversible while you keep the unoptimized master file, which you should: archive the editor export as the source, and treat the optimized file as a build artifact.
Step 1: strip the document shell. Remove the XML declaration when the SVG is inlined in HTML, since the page already declares its encoding. Remove comments and editor metadata elements. Keep the xmlns attribute: an SVG used as an image file needs it, and inlined files are safer with it left in place.
Step 2: decide the title question on purpose. A title element is the accessible name of an inline SVG; when the file is used through an img tag, the alt attribute supplies the name instead. For a decorative icon inlined beside a text label, the title adds nothing and the svg should carry aria-hidden instead. For a standalone meaningful graphic, a logo, a chart, a diagram, keep a clear title or provide the name in the surrounding HTML. The mistake is letting the export decide: editor titles say things like the layer name, which helps nobody. For the exact attributes each delivery method needs, see the accessible SVG markup table.
Step 3: collapse groups and delete empties. Flatten nested groups that carry no transform, opacity, mask, or class. Where a group carries a transform, either keep it or bake the transform into the path coordinates, which most optimizers can do. Delete empty groups, empty defs, and elements with no rendering effect.
Step 4: set precision on purpose, then look. Start with SVGO's default of 3 decimals, or 2 for simple icons: in our test both were visually lossless on an icon, a detailed flag and an illustration. Precision 1 or 0 needs a render check at the smallest size the file ships, because a 24 pixel icon showed 3.47 percent changed pixels at precision 1, and precision 0 erased a fifth of an illustration. Precision rounds every number, including opacity and stroke widths, not just path coordinates. Never round a file you have not looked at afterwards, at the smallest size, at 100 percent and at the largest size it will be shown.
Step 5: merge paths and unify color. Combine paths that share fill, stroke, and opacity into a single path with multiple subpaths. Move shared presentation attributes to the root svg or a single parent group. Replace a fixed brand color with currentColor when the icon should follow text color, which is most interface icons, and keep hard-coded fills for logos and multicolor illustrations where the color is the content.
Step 6: audit the ids and classes that remain. Whatever survives should be there because something uses it: a gradient fill referenced by a path, an id targeted by a use element in a sprite, a class your CSS styles. Rename sprite ids to short, unique names, since ids in inlined SVG share the page's global namespace and a generic id like a gradient named "a" in two files can collide.
Step 7: render-check at three sizes. View the optimized file small (16 to 24 pixels for icons), at layout size, and large. Rounding and path merging errors hide at exactly one of those scales: a merged subpath that fills wrong shows at large size, a rounded corner that collapses shows at small size. Then check the icon in place, in the button or nav it belongs to, in light and dark mode.
What Never to Remove
Every item on this list has broken a real page when an optimizer preset removed it.
- The viewBox. Without it the file cannot scale cleanly, as the viewBox and preserveAspectRatio math shows, and some optimizer configurations remove it when width and height are present. If a tool drops the viewBox, that tool's settings are wrong for web delivery, full stop.
- Ids referenced from elsewhere. Gradient, pattern, mask, clip path, and symbol ids are referenced by url(#id) inside the file, by use hrefs in other files, and sometimes by CSS. Removing an apparently unused def that a stylesheet references produces an icon with a transparent hole where the fill was.
- Classes and data attributes your code uses. Design systems hook styling and occasionally behavior to icon classes. An optimizer that strips classes it cannot see being used is guessing with your interface.
- The title or accessible name on meaningful graphics. Charts, diagrams, and logos used as images need their text alternative wherever it lives. Strip it only from decorative icons, and give those aria-hidden so assistive technology skips them.
- Stroke settings on stroke-based icons. Sets like Lucide and Tabler draw with strokes, and their look depends on stroke width, linecap, and linejoin surviving the pass. Merging and fill conversion settings written for fill icons will mangle a stroke set. The free icons guide compares the major sets and their construction; know which kind you are holding before you optimize it.
- Animation hooks. If an icon or illustration animates with CSS or SMIL, the classes, ids, and sometimes the group structure are the animation's handles. The web animation performance guide covers the rendering side; the optimization rule here is simple: animate first, then optimize around the hooks, then test the animation again.
Icons Are Not Illustrations
The same pass applies to both, but the proportions differ and so do the risks.
Icons are small, geometric, and usually one color. Precision rounding and path merging do most of the work, the files end up tiny, and the main risk is structural: a removed attribute or a collapsed group changing how the glyph renders at 16 pixels.
Illustrations are large, layered, and multicolor. Their weight sits in path count, gradient defs, and occasionally an embedded raster. Rounding must be gentler, merging stops at color boundaries, and the valuable edits are deleting genuinely unused layers and defs and simplifying background shapes nobody sees at final size. Test illustrations at the largest size they will ever render, including retina exports, because simplification artifacts scale up with the artwork. The free vector graphics guide covers sourcing clean vector files in the first place; a well-drawn source file needs half the cleanup of a traced or auto-generated one.
Logos are a third case: optimize conservatively or not at all. A logo file is a brand asset with exact geometry, its colors are content rather than presentation, and the correct deliverable is usually the brand's own file, verified against the source, with metadata stripped and nothing else touched.
Two Figma export settings change what lands in the file before any optimiser runs, outline text and simplify stroke, and Figma's export formats and settings page explains both.
Delivery: Inline, Sprite, or Icon Font
Optimization shrinks each file. Delivery decides how many times the browser pays for it. The major icon libraries offer the same artwork in several formats: Bootstrap Icons, for example, ships individual SVG files, one combined SVG sprite, and an icon font, and states the set works with or without the Bootstrap framework. Choose by how the icons are used, not by habit.
| Method | How it works | Best for | Watch out for |
|---|---|---|---|
| Inline SVG | The svg markup sits in the HTML where the icon appears | A handful of icons per page; icons that need CSS color, size, or animation control | Repeats the markup on every page and every instance unless your framework components it |
| SVG sprite | One file holds symbol definitions; pages reference icons with a use element | Many icons across a site; one cached file serves every page | Ids share the page namespace when inlined; external sprites must be served from your own origin for full browser support |
| Icon font | Icons are glyphs in a font file, placed with CSS classes | Legacy stacks already built on font icons; very simple color needs | Icons inherit font rendering quirks, load as one blocking file, and fail as tofu boxes if the font fails; multicolor is effectively impossible |
| Image file | The SVG loads through an img tag like any picture | Logos, illustrations, and diagrams used once, where CSS control of internals is unnecessary | No styling of internals from page CSS; needs its own accessible name handling |
The current default for new work is inline SVG for the few icons a page shows and a sprite when a system has dozens. Icon fonts persist in older codebases and in libraries that still ship one, and there is rarely a reason to migrate a working font setup urgently, but there is also no case for starting a new one in 2026. Whichever method you choose, optimize the source files first; a sprite built from unedited exports is just the bloat in one file instead of forty.
Tools, and the Settings That Matter
SVGO is the standard open-source optimizer and runs in build pipelines, on the command line, and behind web front ends such as SVGOMG for one-off files. Its plugin system is the point and the danger. The settings that matter most:
- removeViewBox off. Confirm the viewBox survives every run. SVGO 3's preset-default included removeViewBox and removeTitle; SVGO 4's does not, so a pipeline still on version 3, or a config that turns them back on, strips both. For web delivery the viewBox must stay.
- Know what the default preset does to ids and comments. In our test, cleanupIds renamed ids to a and b, which is why prefixed ids matter in sprites. removeComments keeps comments that start with an exclamation mark, so the Font Awesome license comment survived; keep that behaviour for licensed icons.
- Precision set deliberately. The SVGO default of 3 was lossless in our test. The precision setting rounds every number, including opacity and stroke width, so 0 or 1 can delete faint fills and hairlines, not just move curves. Pick 2 or 3 unless you render-check.
- Id handling set to preserve or minify with a prefix. Unprefixed minified ids collide when several optimized files land on one page or in one sprite.
- Class and data attribute removal off unless you have verified nothing styles or selects them.
- One file tested by eye per batch. Run the batch, then diff-render a sample, including the most complex illustration and the smallest icon, before shipping the rest.
Editor export settings prevent half the cleanup. In most vector tools, export with outlines converted where the artwork is final, decimal precision set low, responsive or viewBox-only sizing where offered, and the option that preserves editing capabilities turned off for delivery files, since that option is a common source of embedded extras. Keep the editable master separately, with layers and precision intact, and export delivery files from it on purpose.
Finally, compress what ships. SVG is text, and servers should gzip or brotli it like HTML and CSS. An optimized icon that travels uncompressed gives back a share of the saving on the wire, and the fix is a server setting rather than another editing pass.
Layers headed for an app icon have their own limits, such as clean edges and a centred symbol, covered in the app icon sizes guide.
Before optimising, make sure the SVG came out of the design tool with text outlined where it should be; what each export route keeps and loses, including Illustrator's SVG, EPS and PDF copies, is laid out in the vector file formats guide.
Pre-Ship Checklist
Run this on any icon set, illustration, or logo before it enters a project.
- The master editor file is archived untouched; optimized files are exports, not the only copy.
- No image element or data URI hides inside the file unless the artwork truly is a photo, in which case it ships as a raster format instead.
- Metadata, comments, and editor scaffolding are removed.
- The viewBox is present and the file scales cleanly from 16 pixels to full width.
- Precision is the default 3 or 2 unless the file was render-checked at a lower setting, and the file was checked small, at layout size, and large.
- Paths sharing a fill are merged; shared attributes sit on the root or one parent.
- Interface icons use currentColor where they should follow text; logo and illustration colors are untouched.
- Every remaining id and class is used by the file, the page, or the sprite, and sprite ids are unique.
- Decorative icons carry aria-hidden; meaningful graphics carry a title or a text alternative in the HTML.
- The set's delivery method is chosen on purpose: inline, sprite, or font, with the total before and after weight recorded.
- The license for the source artwork is on file beside it, as the design asset licensing checklist sets out; an optimized file carries the same license duties as the original.
FAQ
Does optimization change an icon's license?
No. Optimization is a technical edit, like resizing a photo. The optimized file is the same artwork under the same license as the source, so an MIT icon set stays MIT with its notice kept, an SIL Open Font License font keeps its license file, and a set whose terms forbid redistribution is still not yours to redistribute just because you cleaned the markup. Keep the license file with the optimized assets. The free icons guide compares what the major sets allow.
How small should an interface icon be?
As small as clean structure gets it, not smaller. A simple one-color glyph on a 24 unit grid usually lands in the low hundreds of bytes after the pass in this guide, and the worked example reached 200 bytes. Chasing double digits by gutting precision and path structure saves almost nothing across a page and makes the file unmaintainable. If an icon is several kilobytes after cleanup, the problem is usually drawing complexity or an embedded extra, not decimals.
Does SVGO remove the viewBox?
Not in version 4. In SVGO 4.1.0 the removeViewBox and removeTitle plugins are not part of the default preset, so the viewBox and title survive a default run. SVGO 3's default preset included both, so a project still on version 3, or a config that enables removeViewBox, will strip the viewBox. Open one output file and confirm it is there.
What precision should I use in SVGO?
Start with the default of 3, or 2 for simple icons. In our November 2026 test, precision 3 and 2 changed no visible pixels on a detailed flag or an illustration, while precision 0 erased a semi-transparent panel and changed a fifth of the illustration's pixels. Precision rounds opacity and stroke widths as well as coordinates, so lower settings need a render check at the smallest size the file ships.
Is an icon font ever the right choice now?
For new work, almost never. Inline SVG and sprites give better rendering, real color control including currentColor, per-icon loading, and no font failure mode. Icon fonts remain reasonable inside legacy systems already built on them, and some libraries still publish one, but starting a new project on a font means choosing the weakest option on purpose.
Can I optimize a logo the same way?
Only the shell, not the drawing. Strip metadata and comments, confirm the viewBox, and stop. Do not merge, round, simplify, or recolor a logo: its geometry and colors are the brand, small changes are brand damage, and the file you should ship is normally the brand owner's own, checked against the source they published. One place a logo should not ship as SVG at all is an email signature; the signature logo size and format guide explains why Gmail and older Outlook versions need a PNG.
Why did my icon turn into a black square after optimizing?
Two usual causes. The pass removed a fill or gradient definition the path referenced, leaving a default fill where a styled one was, or it stripped the classes the stylesheet used to color and size the icon. Restore the file from the master, turn off the plugin that removes defs or classes, and re-run with the render check in Step 7. A black square is the optimizer telling you it guessed about something it could not see. If the file is blank rather than black, or shows only on its own URL, work through the SVG not showing troubleshooting table.
Should product screenshots and photos ever ship as SVG?
No. An SVG that embeds a raster image is a photo with extra markup around it, heavier and worse than the same photo delivered as WebP or AVIF at the sizes the layout needs. The responsive images guide covers sizing those properly. SVG is for artwork drawn as vectors: icons, illustrations, diagrams, and logos.
What to Read Next
If the SVG you are cleaning up is a site icon, pair it with the raster fallbacks covered in the favicon sizes and formats guide, since not every consumer of a favicon reads SVG.
- Free icons for commercial use - MIT, ISC, Apache 2.0, and CC0 icon sets compared, so the files you optimize are files you may use.
- Bootstrap Icons asset page - a 2,078-plus icon MIT library in this directory, shipped as SVG files, a sprite, and a font, so you can compare delivery formats on one real set.
- Free vector graphics for commercial use - sourcing clean vector artwork whose files need less cleanup.
- Image formats: SVG, PNG, JPEG, WebP, AVIF - the format decision that comes before any optimization.
- Web animation performance - what happens after the optimized file starts moving.
- Icon design principles - the drawing rules behind icons that stay legible at 16 pixels.
This guide is maintained by the Lucky Graphics editorial team and reviewed when the tools and libraries it names change their behaviour. The worked example was drawn and measured for this guide in October 2026. The SVGO 4.1.0 test tables were run on November 20, 2026.