Preview SVG inside TypeScript/JavaScript template literals. Mark a template with /*svg*/ before the backtick to get a gutter icon and code lens; open a live preview in a side tab. Supports variables—inputs are provided for each ${...} with sensible defaults inferred from attribute names (e.g. width,
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Preview SVG inside TypeScript and JavaScript template literals. Mark a template with /*svg*/ before the opening backtick to get a live preview in a side tab—with optional inputs for variables and sensible default values.
Features
Live SVG preview – Mark any template literal with /*svg*/ (or /* svg */) immediately before the backtick. A Preview SVG code lens and a gutter icon appear on that line. Click either to open the SVG in a side preview tab.
Variable inputs – If the template uses interpolations like ${width} or ${color}, the preview tab shows a text input for each. Edit values to see the SVG update in real time.
Smart defaults – Defaults are inferred from how variables are used (e.g. in width, fill, stroke). Numbers get values like 100 or 50; colors get #3366cc; coordinates and radius get sensible defaults.
How to use
In a .ts, .tsx, .js, or .jsx file, add /*svg*/ right before the opening backtick of a template literal that contains SVG.
Use the Preview SVG code lens above the line or the eye icon in the gutter to open the preview.
Or run Preview SVG from the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) with the cursor on a line that has a /*svg*/ template.