Opening the preview panel
The preview panel appears in the Explorer sidebar under the name “SVG Preview”. By default, it automatically reveals when you open an SVG file.The panel uses VS Code’s webview technology to render SVG content safely and efficiently.
Auto-reveal behavior
Configure whether the panel automatically opens when you work with SVG files:- Default:
true - Type:
boolean - Description: Automatically reveals and expands the SVG Preview panel when opening SVG files
- Automatically focus when you open an SVG file
- Stay visible as long as an SVG file is open
- Update the preview when you switch between different SVG files
Auto-collapse behavior
Control whether the panel collapses when you close all SVG files:- Default:
true - Type:
boolean - Description: Automatically collapses the SVG Preview panel when closing all SVG files
- Collapse when you close the last open SVG file
- Clear the preview content
- Remain collapsed until you open another SVG file
Live preview updates
The preview panel updates in real-time as you edit your SVG files. Changes are reflected immediately without needing to save the file. The preview system:- Updates after a 500ms debounce to avoid excessive rendering
- Maintains your zoom and pan settings during updates
- Resets zoom when switching to a different SVG file
- Automatically adjusts to theme changes
Preview features
The panel provides several interactive features:- Color picker - Change the
currentColorvalue to see how your SVG adapts to different colors - Dark mode toggle - Switch between light and transparent checkerboard backgrounds
- Zoom controls - Zoom in/out and pan across your SVG
- Optimize button - Trigger SVGO optimization directly from the panel
- File size display - View the current size of your SVG in KB
- Zoom level indicator - See the current zoom percentage
All viewport controls (zoom, pan, center) are documented in detail in the viewport controls page.
CurrentColor configuration
Set the default color that replacescurrentColor in your SVG:
- Default:
#ffffff(white) - Type:
string - Format: Hex color (e.g.,
#ff0000,#f00) - Description: Default color for
currentColorin the SVG preview
- The initial color when the panel opens
- How SVGs using
currentColorare displayed - The preview panel’s color picker initial value
Technical details
The preview panel is implemented using:- Provider:
SvgPreviewProvider(extension.ts:38) - View ID:
betterSvg.preview - Location: Explorer sidebar
- Webview options: Retains context when hidden for better performance
update- Updates the preview with new SVG contentclear- Clears the preview when no SVG is openoptimize- Triggers SVGO optimization
Best practices
- Use the color picker to test how your SVG responds to different
currentColorvalues - Toggle dark background to verify your SVG works on different backgrounds
- Use the optimize button to reduce file size while previewing the results
- Disable auto-collapse if you frequently switch between SVG and other files