SVG Preview & SVG Viewer (PNG Export)

SVG Preview & SVG Viewer (PNG Export), a VS Code extension by Zovo

Live preview beside the editor, zoom at the cursor, scripts never run. SVG preview and SVG viewer for VS Code: pan, viewBox outline, checkerboard or custom background, sprite sheet grid for <symbol>, .svgz, and PNG export at 1x to 8x. Free, offline.

Install in VS CodeOpen the Marketplace page

Free, MIT license. Needs VS Code 1.90.0 or newer. Extension ID zovo.zovo-svg-viewer, version 0.2.1.

Preview SVG files beside the editor, zoom into the details, check the viewBox and export PNGs. Free, no sign-in, works offline.

A 17.2 MB world map SVG open as text on the left and in SVG Viewer on the right, zoomed to 87 % on Europe and Africa. The toolbar has Fit, 1:1, zoom, Checkerboard background, viewBox, Symbols (2059), PNG 2x, Save PNG, Copy PNG, Data URI and Source. The status line reads 1,920 × 972.6 px, viewBox 0 0 1440 729.45, 17.2 MB, 67,566 elements, 2,059 symbols, and the pointer position x 766.2, y 149.6.

Real output from VS Code 1.142 on macOS. The file is the public-domain Physical Map of the World (2021).svg) from Wikimedia Commons (17.2 MB). scripts/readme-shots.mjs installed the packaged extension in a clean VS Code profile, opened the file and saved the window.

Quick start

  1. Install SVG Viewer.
  2. Open an .svg file and click the preview button in the editor title (or press Cmd+K V, Ctrl+K V on Windows and Linux). The preview opens beside the editor and follows your edits before you save.

To view an SVG without the text, right-click it in the Explorer and pick "Open in SVG Viewer", or use "Reopen Editor With..." > SVG Viewer. .svgz files open in SVG Viewer directly. VS Code keeps its own default for .svg, so SVG Viewer never takes over a file you did not ask it to open. "SVG Viewer: Get Started" in the Command Palette opens a short tour.

Questions people ask

Is SVG Preview & SVG Viewer (PNG Export) free?

Yes. SVG Preview & SVG Viewer (PNG Export) is free and MIT licensed.

How do I install SVG Preview & SVG Viewer (PNG Export)?

Click "Install in VS Code" above, or search for zovo.zovo-svg-viewer in the Extensions view.

What people asked the older SVG previews for

Request in rival reviews and issuesSVG Viewer
"You can't zoom in + scroll together", "Preview doesn't keep zoomed in area focused"The wheel zooms at the pointer and dragging pans at any zoom. The view is kept when the file changes and after a reload.
"Never remembers the background color", "Light preview background by default"Checkerboard, white, black, theme or a custom colour. Your pick is kept for the workspace.
"Add setting that shows viewBox", "add dimmed area to depict area outside viewBox"viewBox (V) outlines the viewBox and draws the rest of the picture dimmed around it.
"Support generated SVG files", crashes "when svg image is recreated"The preview watches the file on disk. Files that are rewritten, or deleted and written again, update the picture without an error. A half-written file keeps the last good picture.
"Export sizing or export scale" for PNGPNG at 1x, 2x, 4x, 8x or a set width, saved to a file or copied to the clipboard.
"It does not keep the aspect ratio", "scale to view by default"The picture opens fitted to the view, at its exact aspect ratio.
"Support for prefers-color-scheme"When a file has prefers-color-scheme styles, the Scheme menu shows it in light or dark.
"Doesn't support <symbol>"Sprite sheets show a grid of every symbol with its id. Click one to copy its <use href="#id"/> line.

viewBox outline

viewbox-offset.svg with viewBox on. A dashed red outline labelled viewBox -200 -150 400 300 surrounds the picture. A red circle and a blue rectangle stick out past the top left and right edges, and their outside parts are drawn in the dimmed area.

The outline follows preserveAspectRatio, so letterboxed and sliced pictures show where the viewBox really lands. Files without a viewBox outline their width and height.

Sprite sheets

The Material Design action icon sprite in SVG Viewer: a grid of icons such as 3D rotation, accessibility, alarm and Android, each with its symbol id under it, and a filter box that reads Filter by id.

Files with <symbol> elements get a Symbols button. A file that is only a sprite sheet opens on the grid. Type in the filter box to find an id.

Safe with files from anywhere

hostile-script.svg in SVG Viewer. The status line reads Blocked: 2 scripts, 4 event handlers, 1 foreignObject, 6 external links.

SVG Viewer draws the file as an image. Scripts and event handlers in the SVG never run, and images, fonts or styles from the web are never fetched. The status line lists what was blocked. The viewer page itself has a strict Content Security Policy with no network access, and the extension makes no network calls and collects no data.

Hostile fileWhat happens (checked in a real VS Code)
<script>, onload=, <foreignObject> with HTML, <image href="http://...">Nothing runs, no request leaves VS Code, no dialog opens
XML entity expansion ("billion laughs")The renderer refuses it and a plain message shows. VS Code stays responsive.
width="100000000"Opens fitted. Zoom is capped so the drawn picture stays under 200,000 px.
.svgz that unpacks to 600 MBUnpacking stops at the limit and a message says so

Large files

Files up to 50 MB draw at once (the 17.2 MB world map above opened in 2.1 seconds in the release check). Larger files first show their size and the width, height and viewBox from the first 64 KB, and draw when you click Render it. The limit is the svgViewer.maxFileMB setting. Files over 400 MB are not read.

Light and dark

SVG Viewer in the Light Modern theme. The toolbar and status line use the light theme colours, and the Scheme menu is set to dark, so the sample file draws its dark style.

The toolbar, menus and status line take their colours from your VS Code theme.

Keys

KeyWhat it does
Wheel or pinchZoom at the pointer (setting svgViewer.mouseWheel = scroll makes the wheel pan and Ctrl or Cmd + wheel zoom)
Drag, or Shift + wheelPan
0Fit
1Actual size (1:1)
+ and -Zoom in and out
Arrow keysPan
VviewBox outline
Double-clickZoom in 2x at the pointer (Alt + double-click zooms out)

Settings

SettingDefaultWhat it does
svgViewer.preview.autoOpenfalseOpen the preview beside the editor when you open an .svg file as text
svgViewer.defaultBackgroundcheckerBackground until you pick one in the toolbar
svgViewer.mouseWheelzoomzoom, or scroll (the wheel pans)
svgViewer.maxFileMB50Larger files ask before they draw
svgViewer.askForRatingtrueAsk at most two times for a Marketplace rating
svgViewer.showSupportLinkstrueShow the Sponsor and More free viewers links in the status line

Limits

Privacy

No telemetry, no account and no network calls. The rating question is shown at most two times and only opens the Marketplace page when you click Rate it.

License

MIT. The sample files in samples/real/ keep their own licences (W3C test suite licence, public domain, Apache 2.0); see samples/README.md.

Guides

Install SVG Preview & SVG Viewer (PNG Export)

Click the button to open VS Code and install it, or press Ctrl+P (Cmd+P on macOS) in VS Code and run ext install zovo.zovo-svg-viewer.

Free, MIT license. Needs VS Code 1.90.0 or newer. Extension ID zovo.zovo-svg-viewer, version 0.2.1.

Source code and issues are on GitHub.

All our VS Code extensions

Support this work

If this extension saves you time, you can support the work on GitHub Sponsors. Monthly tiers start at $5, and one-time tiers start at $15. Sponsorship is optional, and the tool works the same without it.

Need your format supported?

Open a format request with a sample file, and I reply there whether it can be done. For USD 299 once, through this GitHub Sponsors tier, I add your file format or a missing feature to this extension, with tests, within 7 days.