SVG Viewer
Open or paste SVG code to preview it, zoom, and read its width, height, viewBox and element count. Scripts and event handlers are flagged and never executed.
The interactive tool loads here when JavaScript runs.
About this toolWhat is the SVG Viewer?
The SVG Viewer previews SVG files and pasted SVG markup, and shows the facts that decide how an SVG behaves on a page: its width and height attributes, its viewBox, how many elements it contains and its size in bytes. You can zoom from 10% to 300%, copy the code or download it again.
The preview is rendered as an image, through an img element with a data: URL. In that mode browsers never run scripts, never fire event handlers and never fetch external files referenced by the SVG. That makes it safe to open an SVG from an unknown source. If the file does contain a script element, on* event handlers, javascript: links or foreignObject, the information panel lists them so you know before you put the file anywhere else.
Files up to 5 MB are read locally. Nothing is uploaded.
- Safe preview through an image, with no script execution
- Flags script, on* handlers, javascript: links and foreignObject
- Width, height, viewBox, element count and byte size
- Zoom from 10% to 300%
- Upload, paste or load a sample; copy and download
- Local processing with no uploads
Updated
How to use the SVG Viewer
- Click Upload SVG File and choose an .svg file, paste markup into Or Paste SVG Code, or click Load Sample.
- Read the SVG Information panel: Width, Height, ViewBox, Elements, File Size, and any active content found.
- Use the zoom buttons above the SVG Preview to inspect detail, and the reset button to return to 100%.
- Check the Code View to read the markup as plain text.
- Click Copy Code or Download to take the SVG with you.
Worked examples
A typical icon
Input
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>
Output
Width 24, Height 24, ViewBox 0 0 24 24, Elements 1
The element count excludes the root svg element. Remove width and height and the panel shows auto, meaning the icon will scale to its container.
An SVG with a hidden payload
Input
<svg xmlns="http://www.w3.org/2000/svg" onload="alert(1)"><script>alert(2)</script></svg>
Output
Active content (not executed in the preview): <script> element, onload event handler
The preview stays blank and no alert appears. Inline the same markup into a web page and both would run.
Background and insight
SVG became a W3C Recommendation in 2001, and SVG 1.1 Second Edition (2011) is still the version most tools target. An SVG is an XML document, which is why it can carry far more than shapes: CSS, links, embedded HTML through foreignObject, and JavaScript through script elements and attributes such as onload.
How an SVG is embedded decides what that content can do. Inline svg markup in the page, or HTML built with innerHTML, runs event handlers in the page context, which is a classic stored cross-site scripting route when users can upload SVG avatars or icons. An img element, a CSS background-image or a sandboxed iframe treats the file as a picture: no script runs and no external resources load. Serving user uploads from a separate domain with Content-Type image/svg+xml and a restrictive Content-Security-Policy adds defence in depth when people open the file directly.
The viewBox is the most misunderstood attribute. It defines the internal coordinate system as min-x, min-y, width and height, while the width and height attributes set the size on the page. An icon with viewBox="0 0 24 24" and no width or height can scale to any size; the same icon with width="24" is pinned to 24 pixels unless CSS overrides it.
Common use cases
Vetting third-party icons
Check SVGs from icon sites, designers or user uploads for scripts and event handlers before adding them to a product.
Debugging scaling problems
See at a glance whether an icon has a viewBox and fixed width and height, the usual reason it will not resize with CSS.
Reviewing exported files
Open SVGs exported from Figma, Illustrator or Inkscape and see how many elements they produced before optimising.
Quick previews without an editor
Paste SVG markup from code, a ticket or a chat message and see what it draws.
Tips and limitations
- External images and web fonts referenced by URL do not load in the preview, because SVG used as an image cannot fetch other files. Embed them or convert text to paths.
- A missing viewBox is the most common reason an SVG crops or refuses to scale. Add one that matches the original width and height.
- Large element counts usually come from design tool exports. An optimiser such as SVGO can often cut size by half.
- For user uploads, render SVG with img or as a CSS background, never with innerHTML or dangerouslySetInnerHTML.
- Uploads are limited to 5 MB. Pasted code has no limit, but very large files make the code view slow.
Sources and further reading
- Scalable Vector Graphics (SVG) 1.1 (Second Edition), W3C
- viewBox, MDN Web Docs
- Cross Site Scripting Prevention Cheat Sheet, OWASP. Why inlined user SVG can run script
Frequently asked questions
Can an SVG file contain malicious code?
Yes. SVG is XML and can include script elements, event handler attributes like onload, javascript: links and embedded HTML. Those run when the SVG is inlined into a page or opened directly in a browser tab. This viewer renders through an image element, where none of that executes, and lists what it found.
Is it safe to display user-uploaded SVGs with an img tag?
An img tag is the safe default because browsers block scripts and external requests in SVG images. The remaining risk is someone opening the file URL directly, so serve uploads from a separate domain or with a Content-Security-Policy that blocks scripts.
What does the viewBox attribute in an SVG do?
It sets the internal coordinate system: min-x, min-y, width and height. Shapes are drawn in those units and then scaled to the element's actual size. Without a viewBox the drawing cannot scale and is clipped instead.
Why does my SVG show at the wrong size on my page?
Usually because fixed width and height attributes pin it to one size, or because there is no viewBox to scale from. Open it here to see both values. Keep the viewBox, remove width and height, and size it with CSS.
Why are fonts or images missing in the SVG preview?
When SVG is rendered as an image, browsers do not load external resources such as web fonts, linked images or external stylesheets. The same will happen in any img tag on your site. Embed the image as a data URI and convert text to outlines.
Does the SVG viewer upload my files?
No. The file is read with FileReader and parsed with the browser's DOMParser in your tab. The preview, the element count and the active-content check all run locally, so private icons and unreleased artwork never leave your machine.
Is there an in-depth guide to the SVG Viewer?
Yes. “SVG viewBox, Sizing and Script Safety for Developers” covers the background, how it works, common pitfalls and worked examples. Read the full guide.
Related Tools You May Like
Free, in-browser tools that pair well with this one.