A practical guide to optimizing SVG files for the web — reducing file size, cleaning up editor bloat, and using SVGs effectively in your projects.
SVG is the best format for icons, logos, and illustrations on the web — it's resolution-independent, scriptable, and often tiny. But SVGs exported from design tools like Figma, Illustrator, or Inkscape are bloated with unnecessary data. This guide shows you how to optimize them.
When you export an SVG from a design tool, it includes metadata the browser never uses:
fill="black" is redundant if it's already the default)47.382910 instead of 47.4)A logo exported from Figma might be 8KB. After optimization, the same logo is 1.2KB — an 85% reduction.
SVGO (SVG Optimizer) is the industry-standard tool. Install it globally or use it via an online tool:
npm install -g svgo
svgo input.svg -o output.svg
# Optimize all SVGs in a folder
svgo -f ./src/assets/icons
You can also use HeoLab's SVG Optimizer directly in your browser — no installation needed.
| Optimization | Typical Savings |
|---|---|
| Remove editor metadata | 5–15% |
| Clean up number precision | 10–20% |
| Remove hidden elements | 5–30% |
| Merge path data | 10–25% |
| Remove default attributes | 3–8% |
viewBox, not width/height<!-- Bad: fixed size -->
<svg width="24" height="24">
<!-- Good: responsive -->
<svg viewBox="0 0 24 24">
The viewBox makes SVGs scale correctly with CSS. You can set size via CSS without touching the SVG file.
currentColor for theme support<svg viewBox="0 0 24 24" fill="currentColor">
<path d="..."/>
</svg>
Now the icon inherits the parent element's color property — perfect for dark mode.
| Method | Pros | Cons |
|---|---|---|
<img src="icon.svg"> | Cached, simple | Can't style with CSS |
Inline <svg> | Fully styleable | No caching, clutters HTML |
CSS background-image | Cached | Can't use currentColor |
<use> sprite | Cached + styleable | More setup |
For icons used across many pages, an SVG sprite with <use> gives you the best of both worlds.
SVG fonts are deprecated. Use WOFF2 or system fonts instead.
SVG is XML text — it compresses extremely well. Make sure your server sends Content-Encoding: gzip or Content-Encoding: br. A 3KB SVG often becomes 800 bytes over the wire.
Add SVG optimization to your build pipeline so developers don't need to think about it:
// package.json
{
"scripts": {
"optimize-svg": "svgo -f src/assets/icons",
"build": "npm run optimize-svg && next build"
}
}
Use Chrome DevTools Network tab to compare before/after. For a page with 20 icons, switching from un-optimized to optimized SVGs can save 50–100KB — a meaningful improvement for initial load.
viewBox + currentColor for flexible, themeable icons