What is an SVG file?
An SVG (Scalable Vector Graphics) file is a picture written as text: a list of shapes, lines, curves and colours rather than a grid of pixels. Because the shapes are redrawn every time the file is shown, an SVG stays sharp at any size, from a 16 px icon to a poster.
That makes SVG ideal for logos, icons and diagrams, and a poor choice for photos. If you have a logo as a PNG or JPG and want it as an SVG, it has to be traced into shapes.
What is inside an SVG
The W3C, which publishes the standard, defines SVG as “a language based on XML for describing two-dimensional vector and mixed vector/raster graphics”. In practice an SVG file is plain text you can open in any text editor. A simple badge could look like this:
<svg xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 240 120">
<rect width="240" height="120"
rx="16" fill="#1d4ed8"/>
<circle cx="60" cy="60" r="36"
fill="#facc15"/>
</svg>The viewBox sets up a drawing area 240 units wide and 120 high; the rectangle and circle are placed on it. Show that file at 240 pixels wide or 2,400, and the browser draws the same rectangle and circle at that size, with clean edges both times. MDN puts it this way: compared with JPEG or PNG, SVG images “can be rendered at any size without loss of quality”.
An SVG can also contain embedded bitmap images, text, filter effects, animation and even script. The SVG 2 specification notes that “script can be used to create interactive documents”. That is why our SVG to PNG andResize SVG tools refuse files containing scripts, event handlers or links to outside files rather than open them.
What SVG is good for, and what it is not
MDN’s format guide describes SVG files as “ideal for diagrams, icons, and other images which can be accurately drawn at any size”, and “not generally useful for strictly bitmap or photographic images”. In short:
- Good: logos, icons, illustrations with flat colours, charts, maps, diagrams, cutting and engraving files.
- Poor: photos, scans with texture, anything with millions of subtly different colours.
For simple artwork SVG files are often tiny, because a few shape descriptions replace thousands of pixels. They can also be shrunk further by removing editor leftovers and shortening numbers.
How to open an SVG file
- A web browser. Drag the file into a browser window. caniuse.com lists basic SVG support in every current version of Chrome, Edge, Firefox, Safari and Opera, and puts the share of browsers in use that support it at 97.58%.
- A text editor, to read or change the code. MDN notes SVG can be “created and edited with any text editor or with drawing software”.
- A vector drawing program, to edit the shapes visually.
The usual extension is .svg. The W3C registration also names .svgz, which is an SVG compressed with gzip.
Converting SVG to PNG or JPG
When an upload form or program asks for PNG or JPG, an SVG will not do, so you convert it. Converting an SVG to PNG is called rendering: the shapes are drawn once onto a pixel grid of the size you choose. Pick the largest size you will need, because the PNG cannot be enlarged later without going soft.
Use the SVG to JPG converter when a JPG is required; it fills transparent areas with a colour you pick. To change an SVG’s stated width and height without touching its shapes, useResize SVG.
Converting an image to SVG
Going the other way is harder. A PNG or JPG has no shapes to read, so they have to be worked out by tracing: grouping pixels into colour areas and drawing paths around them. The SVG converter does this in your browser. It gives clean results for logos and line art, and blotchy, oversized results for photos. Our guide onhow to convert an image to SVG covers the settings, andSVG vs PNG helps you decide whether you need an SVG at all.