Instantly crop empty spaces & trim viewBox margins in SVG files. Super fast, zero dependencies. Works across VS Code, Cursor, Antigravity IDE, VSCodium, and Windsurf.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
⚡ Auto Crop ViewBox: Mathematically computes the exact bounding box of paths, shapes (<rect>, <circle>, <ellipse>, <line>, <polygon>, <polyline>), and transformed groups to fit your vector tightly.
💡 Quick Fix (Ctrl+.): Get an instant lightbulb suggestion to trim empty margins whenever you're viewing an SVG.
📁 Explorer Batch Processing: Right-click any .svg file or multiple selected files in the explorer sidebar to crop them all at once.
📐 Stroke-Aware: Automatically accounts for stroke-width expansion so borders never get clipped.
🏎️ Ultra Fast & Lightweight: Bundled with esbuild into a single ~48 KB file with <5ms activation time and zero runtime dependencies.
🔄 Native Undo: Full Ctrl+Z support when cropping files in the editor.
📜 Clean Logging: Dedicated Auto SVG Crop output panel for debugging and batch status.
How to Use
1. Quick Fix Lightbulb
Open any .svg file, click inside the code, and press Ctrl + . (or Cmd + . on macOS) -> select "Auto SVG Crop: Trim empty margins & adjust viewBox".
2. Context Menu
In Editor: Right-click inside any SVG document and select "Auto SVG Crop: Crop Current SVG".
In Explorer: Right-click on one or more .svg files in the file tree and select "Auto SVG Crop: Crop SVG File(s)".
3. Command Palette
Press Ctrl + Shift + P (or Cmd + Shift + P), type Auto SVG Crop, and hit Enter.
Configuration
You can customize the behavior in your VS Code settings (settings.json):
Setting
Type
Default
Description
autoSvgCrop.precision
number
2
Number of decimal places to round coordinates in viewBox.
autoSvgCrop.padding
number
0
Extra padding percentage around the vector content (e.g. 5 for 5%).
autoSvgCrop.removeDimensions
boolean
true
Removes fixed width and height attributes so the SVG stays responsive.
autoSvgCrop.cropOnSave
boolean
false
Automatically crop SVG files whenever you save.
autoSvgCrop.showNotifications
boolean
true
Show toast notifications with the percentage of empty space trimmed.