Skip to content

midudev/better-svg

Repository files navigation

Better SVG

image

The ultimate Visual Studio Code extension for SVG development. Real-time preview, integrated SVGO optimization, and seamless framework support.

made-for-VSCode SVG Badge SVGO Badge GitHub stars

Features

  • Interactive Preview Editor: Open any .svg file to get a powerful editor with a live preview side-by-side.
  • 🖼️ Explorer Preview: A dedicated "SVG Preview" panel in the Explorer view that tracks your active SVG file automatically.
  • 🎨 Smart Hover Preview: Hover over any SVG code in your source files to see an instant preview and optimization options.
  • 📑 Gutter Icons: Small SVG icons appear next to the line numbers where SVGs are defined in your code.
  • 🔍 Advanced Viewport Controls: Zoom with click/Alt+click, scroll with Alt, and drag to pan through your graphics.
  • 🌓 Contextual Visualization: Toggle dark backgrounds and grid overlays to see how your SVGs look in different environments.
  • 🌈 currentColor Control: Dynamically change the currentColor value to test your icons with different theme colors.

Supported Files

Better SVG isn't just for .svg files. It understands SVG syntax inside a wide range of modern web frameworks:

  • Static: .svg, .xml, .html
  • React: .jsx, .tsx
  • Vue: .vue
  • Astro: .astro
  • Svelte: .svelte
  • PHP: .php
  • Laravel Blade: .blade.php
  • Liquid (Shopify): .liquid
  • Django: django-html templates
  • EJS: .ejs
  • ERB (Ruby): .erb

The extension automatically detects SVG tags within these files, providing gutter icons, hover previews, and framework-aware optimization.

Optimization

Integrated SVGO power allows you to shrink your SVGs without leaving the editor.

Ways to optimize:

  1. Toolbar Button: Use the ⚡ icon in the SVG editor title bar.
  2. Context Menu: Right-click an SVG file in the Explorer and select Optimize SVG.
  3. From Hover: Hover over an inline SVG in your code and click the ⚡ Optimize SVG action link.

Smart Framework Support

When optimizing inline SVGs (like in React or Vue), Better SVG:

  • Preserves framework-specific attributes (e.g., v-if, on:click, className).
  • Handles JSX interpolation and spread operators ({...props}).
  • Maintains the coding style of the host file.

Configuration

Customize your workflow through Settings → Extensions → Better SVG:

Preview & UI

Setting Type Default Description
betterSvg.autoReveal boolean true Automatically reveal and expand the SVG Preview panel in Explorer when opening SVG files.
betterSvg.autoCollapse boolean true Automatically collapse the SVG Preview panel when no SVG files are active.
betterSvg.enableHover boolean true Enable the hover preview when mouse is over SVG code.
betterSvg.showGutterPreview boolean true Show small preview icons next to line numbers in the gutter.
betterSvg.defaultColor string "#ffffff" The hex color used to replace currentColor in previews.

Optimization (SVGO)

Setting Type Default Description
betterSvg.removeClasses boolean true Remove class attributes during optimization. Only applies to standalone .svg files; inline framework SVGs always keep their classes.
betterSvg.removeComments boolean true Remove comments from the SVG during optimization.
betterSvg.removeDoctype boolean true Remove the <!DOCTYPE> declaration during optimization.
betterSvg.cleanupIds boolean false Minify and remove unused IDs. Disabled by default because it can break sprites, references and animations.
betterSvg.floatPrecision number 3 Number of decimal places to keep for numeric values (lower means smaller files but less precision).
betterSvg.multipass boolean true Run SVGO multiple times until the output stops shrinking for better compression.

License

Apache-2.0 license

About

Extension to improve working with SVGs on Visual Studio Code, Cursor and other editors

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Contributors