Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

SVG viewer

Paste SVG code or choose an SVG file and see it drawn straight away. The page shows its size, its viewBox, how many elements it has, and the browser's own error message if the code is broken.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Background
Show it

Scripts, event attributes and script links are removed before the preview is drawn.

Preview
Your SVG drawn as an image

240 × 120 pxSize read from width and height

  • No scripts found
viewBox
0 0 240 120
width and height
240 × 120
Elements
10
Code size
541 bytes
Elements by tag
TagCount
stop2
circle1
defs1
g1
linearGradient1
path1
rect1
svg1
text1

How to use the SVG Viewer

  1. Paste your code into SVG code, or use Or choose an SVG file. The file is read on your device.
  2. Pick Light, Dark or Checkerboard under Background, and Fit the box or Real size under Show it.
  3. Read the size, the viewBox, the number of Elements and the table of tags. A red message gives the line and column of any mistake.
  4. To save a picture, type a PNG width in pixels, choose a background and press Download PNG.

How do I view an SVG file or SVG code?

Paste the code into the box. The picture appears in the preview as you type, and the page reads its size from the code. The example is 541 bytes with 10 elements, and the page reports 240 × 120 px. If you have a file, choose it with Or choose an SVG file. The file is opened on your device and is not uploaded.

Use the three backgrounds to check how the picture looks on different pages. A white logo disappears on Light and shows well on Dark. The checkerboard shows which parts are see-through: a see-through area lets the squares show. Fit the box scales the picture to the preview, and Real size shows it at the size the code gives it, so a 24 pixel icon stays small.

The preview is a picture, not a live page. It does not run scripts and it cannot load pictures or fonts from other addresses. A font that is only on your computer may look different from how it looks for other people.

Is it safe to preview an SVG I did not write?

An SVG is a text file, and it can carry more than shapes. It can hold script elements, event attributes such as onclick, and links that start with javascript:. Opened as a page, those can run. For that reason this viewer cleans the code first and removes them before anything is drawn. A chip above the facts tells you how many were found.

The preview is also shown as an image. MDN explains that when an SVG is used as an image, JavaScript is disabled and outside files, such as pictures and stylesheets, are not loaded. So there are two layers: the cleaning, and the image rules of the browser. The table shows what the cleaning does to four small inputs. In the first one, 1 script is removed and the shapes stay.

A code check is not a security review. Do not paste an SVG into other software just because it passed here, and keep your own copy of the original file: the cleaned text is used for the preview and the PNG only.

What the cleaning removes or adds
CaseInputWhat is drawn
A script element<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script><rect/></svg><svg xmlns="http://www.w3.org/2000/svg"><rect/></svg>
An event attribute<svg xmlns="http://www.w3.org/2000/svg"><rect onclick="alert(1)"/></svg><svg xmlns="http://www.w3.org/2000/svg"><rect/></svg>
A script link<svg xmlns="http://www.w3.org/2000/svg"><a href="javascript:alert(1)"><rect/></a></svg><svg xmlns="http://www.w3.org/2000/svg"><a><rect/></a></svg>
No namespace<svg><rect/></svg><svg xmlns="http://www.w3.org/2000/svg"><rect/></svg>

Why does my SVG not show up?

The first check is done by the browser's own XML parser, so the message is the one the browser gives. It names the line and column of the first mistake, and the page shows that line with a caret. The usual causes are a tag that is never closed or is closed in the wrong order, such as <g> closed by </svg>, an attribute value without quotes, and a plain & in text, which must be written as &amp;.

Another common cause is a missing namespace. A standalone SVG file must say xmlns="http://www.w3.org/2000/svg" on the root element. MDN states that the namespace has to be declared for XML files, and that without it a program shows the markup or an error. Inline SVG in an HTML page does not need it. This viewer adds the namespace for the preview when it is missing and says so in a chip, but your file still needs the line.

A third cause is a missing size. Without a viewBox or a width and height, some programs draw the picture at an odd size or cut it off. The facts show what the code sets, so you can add what is missing.

What do width, height and viewBox mean?

The width and height say how large the picture is drawn. The viewBox says which part of the drawing space is shown, as four numbers: left, top, width and height. When both are present, the browser scales the viewBox to fill the width and height. In the example, the width and height are 240 by 120 and the viewBox is 0 0 240 120, so one unit in the code is one pixel.

When only the viewBox is set, the picture can be scaled to any size and keeps its shape, which is why icons usually have a viewBox and no width and height. The table shows what this page reads for five small inputs. Lengths in inches are converted to pixels at 96 per inch.

The size this page reads from the code
CaseRoot tagSize
width and height<svg width="240" height="120"/>240 × 120 px
only a viewBox<svg viewBox="0 0 24 24"/>24 × 24 px
a width and a viewBox<svg width="300" viewBox="0 0 100 50"/>300 × 150 px
sizes in inches<svg width="1in" height="0.5in"/>96 × 48 px
no size at all<svg/>No size set

If the code has no size at all, the page says so, and you cannot save a PNG until you add a width and height or a viewBox. The PNG height always follows the shape of the picture.

How many elements does my SVG have?

The page counts every element in the cleaned code and lists the most common tags. The example has 10 elements: stop 2, circle 1, defs 1, g 1, linearGradient 1, path 1, rect 1, svg 1, text 1. The most common is stop, with 2. A tag such as path holds one shape, g groups shapes together, and defs holds things that are drawn only when something refers to them.

A high count points to a file that may be heavy for a web page. An exported drawing with thousands of paths loads slower than a simple icon. Look at the code size and the tag table, then simplify the drawing in your design tool if the file is larger than you expect. To turn the drawing into a PNG at several fixed sizes, use the SVG to PNG tool.

Use it with

Questions

How do I view SVG code?

Paste it into the box. The picture is drawn as you type, and the page reports its size, viewBox and element count. The example reads as 240 × 120 px with 10 elements.

Does it run the scripts in my SVG?

No. Script elements, event attributes and javascript: links are removed first, and the preview is an image, where the browser does not run scripts.

Why does it say it could not read my SVG?

The browser's XML parser found a mistake, such as a tag that is not closed. The message gives the line and column of the first one.

What is the viewBox?

It is four numbers (left, top, width, height) that say which part of the drawing is shown. With a viewBox the picture scales to any size without changing shape.

Why is my SVG missing xmlns?

A standalone SVG file needs xmlns="http://www.w3.org/2000/svg" on the root tag. The viewer adds it for the preview and tells you, but add it to your file too.

Is my SVG uploaded anywhere?

No. The code or file is read and drawn in your browser and is not sent or stored.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.