Skip to content
UniKit

SVG preview

Preview SVG markup or a .svg file in the browser: scripts, foreignObject, on* event attributes and external references are stripped (with an optional DOMPurify pass), and the intrinsic size, aspect ratio, viewBox and longest-side-fitted display size are reported.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

SVG source

Paste SVG markup or pick a .svg file; scripts, event attributes and external references are stripped before rendering.

SVG markup
480px

Preview & details

Rendering goes through a Blob URL and an <img>, so the SVG is never injected into the page DOM; the display size scales down to fit the longest side.

Paste or upload SVG markup to preview it immediately.

What this tool does

  • Eyeball an SVG exported from a design tool before opening it elsewhere: paste it and see the real render without creating an HTML file.
  • Check that a third-party SVG is safe to embed: scripts, foreignObject, on* handlers and external references are stripped before rendering, which closes the usual XSS holes.
  • Debug "my icon is cut off": compare the intrinsic size (with pt/cm converted), the viewBox and the longest-side-fitted display size.
  • Confirm the aspect ratio when adapting icons: when viewBox and width/height disagree, width/height wins and the size source is labelled explicitly.

Example

Input

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><rect width="24" height="24" fill="#0ea5e9"/></svg>

Output

The preview renders a 24 × 24 blue square and the details panel reports intrinsic size 24 × 24, ratio 1:1, size source width / height attributes, display size 24 × 24, viewBox 0 0 24 24 and removed counts 0/0/0/0.

Rendering goes through a Blob URL and an <img>, so the SVG never enters the page DOM; even if the sanitiser misses something, scripts stay inside the image sandbox.

Frequently asked questions

Why is inlining SVG risky?

An inline SVG is part of the live document: its <script> runs, attributes such as onload fire, and an external <use href> can trigger requests. This tool therefore renders inside an <img> with a Blob URL and sanitises first.

What exactly gets stripped?

The regex pass removes <script> (paired and self-closing), <foreignObject>, every on* event attribute, href / xlink:href values that are not #anchors, and the javascript: scheme. Turning DOMPurify off leaves just that layer; turning it on adds a DOM-level pass on top.

How are the size and ratio computed?

width / height are read first and CSS units are converted (pt = 4/3 px, in = 96 px, cm = 96/2.54 px). If neither exists, the last two viewBox numbers are used; otherwise 300 × 150 is assumed and the size source makes that explicit.

Why does a percentage size fall back?

width="100%" has no resolvable pixel value without a parent container, and the SVG spec then treats it as 300 × 150 (or the viewBox). This tool matches that behaviour and flags both the percentage and the size source.

What is the difference between intrinsic and display size?

Intrinsic size is what the SVG declares about itself; display size is the actual pixel size after scaling down to the "preview longest side" slider limit. Raising the slider only lifts the cap — it never upscales beyond the intrinsic size.

Keywords:svg-previewdoMPurify svg

Related tools