Web Performance

SVG Optimization: Slash File Sizes Without Losing Quality

By Harto Atelier·April 1, 2026·7 min read

SVGs are beloved for their scalability and small size, but unoptimized SVGs can be surprisingly bloated. Files exported from design tools carry metadata, unnecessary elements, and redundant code that multiply file size. Proper optimization typically reduces SVG file size by 30-80% with zero quality loss.

Why SVGs Need Optimization

Design tools like Illustrator, Figma, and Sketch export SVGs that prioritize editability over efficiency. They include:

  • Editor metadata: Tool names, versions, generator comments
  • Unused definitions: Gradients, filters, and symbols that aren't referenced
  • Redundant attributes: Default values that don't need to be specified
  • Unnecessary precision: Coordinate values with 15 decimal places when 2 suffice
  • Hidden elements: Invisible layers, empty groups, zero-opacity shapes
  • Unoptimized paths: Paths with redundant points or suboptimal commands

All this bloat slows downloads, increases render time, and wastes bandwidth.

Common SVG Bloat Sources

Illustrator Export

Illustrator SVGs commonly include:

  • Entire XML doctype declarations
  • Adobe-specific namespaces and metadata
  • Illustrator layer names and IDs
  • Unused gradient and filter definitions

Figma Export

Figma exports are generally cleaner but still include:

  • Excessive decimal precision
  • Default attribute values
  • Redundant group elements

Complex Illustrations

Detailed illustrations can have:

  • Thousands of path points that could be simplified
  • Overlapping shapes that could be merged
  • Duplicate elements that could be reused via <use>

SVGO: The Standard Optimizer

SVGO (SVG Optimizer) is the de facto standard for SVG optimization. It's a Node.js tool that applies a series of plugins to clean up SVGs.

Installation and Usage

# Install
npm install -g svgo

# Optimize a single file
svgo input.svg -o output.svg

# Optimize with custom config
svgo --config svgo.config.js input.svg

# Batch optimize
svgo -f ./svg-folder -o ./optimized-folder

Key SVGO Plugins

  • removeDoctype: Strips XML doctype
  • removeXMLProcInst: Removes XML processing instructions
  • removeComments: Strips all comments
  • removeMetadata: Removes <metadata> elements
  • removeEditorsNSData: Cleans editor namespaces
  • cleanupAttrs: Removes unnecessary whitespace in attributes
  • mergePaths: Combines adjacent paths
  • convertPathData: Optimizes path commands
  • removeUnusedNS: Strips unused namespace declarations
  • cleanupNumericValues: Rounds numbers to reasonable precision

Recommended Configuration

// svgo.config.js
module.exports = {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          removeViewBox: false,       // Keep viewBox for scaling
          cleanupIds: false,          // Preserve IDs if using CSS/JS
        },
      },
    },
    'removeDimensions',               // Use viewBox instead of width/height
    {
      name: 'removeAttrs',
      params: { attrs: ['data-name'] },
    },
  ],
};

Manual Optimization Techniques

1. Simplify Paths

Complex paths with hundreds of points can often be simplified with minimal visual impact. In Illustrator: Object → Path → Simplify. In code: reduce decimal precision.

<!-- Before: excessive precision -->
<path d="M12.345678 23.456789L45.678901 67.890123"/>

<!-- After: 1 decimal point is usually sufficient -->
<path d="M12.3 23.5L45.7 67.9"/>

2. Use <use> for Repeated Elements

If the same shape appears multiple times, define it once and reference it:

<defs>
  <circle id="dot" r="5"/>
</defs>
<use href="#dot" x="10" y="10"/>
<use href="#dot" x="30" y="10"/>
<use href="#dot" x="50" y="10"/>

3. Remove Invisible Elements

Delete elements with:

  • display="none" or visibility="hidden"
  • opacity="0"
  • Zero dimensions (width="0" or height="0")
  • Clipped entirely outside viewBox

4. Prefer CSS over Presentation Attributes

Inline styles or CSS classes can replace repetitive presentation attributes:

<!-- Before: repeated attributes -->
<circle fill="#713EFD" stroke="#282625" stroke-width="2" cx="10" cy="10" r="5"/>
<circle fill="#713EFD" stroke="#282625" stroke-width="2" cx="30" cy="10" r="5"/>

<!-- After: CSS class -->
<style>.dot { fill: #713EFD; stroke: #282625; stroke-width: 2; }</style>
<circle class="dot" cx="10" cy="10" r="5"/>
<circle class="dot" cx="30" cy="10" r="5"/>

5. Use Shapes Instead of Paths

SVG primitive shapes (<rect>, <circle>, <ellipse>) are more compact than equivalent <path> data:

<!-- Path version: 45 chars -->
<path d="M0 0h100v100H0z"/>

<!-- Rect version: 28 chars -->
<rect width="100" height="100"/>

Build Pipeline Integration

Automate SVG optimization in your build process:

Webpack

// webpack.config.js
module.exports = {
  module: {
    rules: [{
      test: /\.svg$/,
      use: ['@svgr/webpack', 'svgo-loader'],
    }],
  },
};

Vite

// vite.config.js
import svgr from 'vite-plugin-svgr';

export default {
  plugins: [svgr({ svgrOptions: { svgo: true } })],
};

What NOT to Optimize

  • Don't remove viewBox: Essential for responsive scaling
  • Don't remove IDs you reference: If CSS or JS targets specific IDs, keep them
  • Don't over-simplify paths: Aggressive simplification distorts shapes
  • Don't remove accessibility attributes: Keep aria-labels, titles, and descriptions

Measuring Results

Track optimization impact:

  • File size: Before and after in bytes
  • Gzip size: SVGs compress well; check compressed size too
  • Visual diff: Compare renders to ensure no visible changes
  • Render performance: Complex SVGs can be slow to render even if small

Optimize Your SVGs

Ready to slim down your SVG files? Our SVG Optimizer applies industry-standard SVGO optimization with a visual interface. Upload SVGs, preview optimized output, compare before/after, and download cleaned files. See exactly how much space you're saving—often 50% or more.

Every kilobyte matters for web performance. Optimize once, benefit on every page load.