Optimization methods
Method 1: Toolbar button
The quickest way to optimize an SVG file is using the toolbar button:Click the optimize button
Look for the lightning bolt (⚡) icon in the editor toolbar at the top-right corner.
Method 2: Command palette
You can also optimize SVG files using the command palette:Method 3: Hover preview
For inline SVGs in your code, you can optimize them directly from the hover preview:Hover over an inline SVG
In any supported file (React, Vue, Svelte, Astro, HTML, etc.), hover over an SVG element.
How optimization works
Full file optimization
When optimizing complete.svg files (methods 1 and 2), Better SVG:
- Removes XML declarations and doctypes
- Removes comments
- Cleans up unnecessary attributes
- Removes
classattributes (configurable) - Removes
xmlns:xlinkandxml:spaceattributes - Runs SVGO’s preset-default with multipass enabled
Inline SVG optimization
When optimizing inline SVGs (method 3), Better SVG:- Preserves
classattributes (important for styling) - Preserves framework-specific attributes (see Framework support)
- Detects JSX syntax and handles it appropriately
- Converts JSX to valid SVG, optimizes, then converts back
Configuration
You can customize optimization behavior in your VS Code settings:false if you want to preserve class attributes even in full file optimization.
Tips for best results
- Before optimization: Always commit your changes to version control first, so you can review the optimization diff
- Inline SVGs: Use the hover preview method to preserve framework-specific attributes and class names
- File size: Optimization typically saves 20-40% on file size depending on the SVG source
- Quality: SVGO optimization is lossless - your SVG will look exactly the same but with a smaller file size