Is SVG lossy or lossless? And what SVGZ is

SVG is lossless in effect: it stores shapes as text and discards nothing when saved or scaled. Where quality can still be lost, and what an SVGZ file is.

Published

SVG is lossless, in the sense that matters: saving a drawing as SVG discards nothing, and opening, scaling and saving it again does not wear it down. Strictly, the words lossy and lossless describe ways of compressing pixels, and an SVG has neither pixels nor compression. It is a text file that lists shapes. If an exam or a form wants one word, the word is lossless.

Why the question does not quite fit

Lossy and lossless are two ways of shrinking a picture made of pixels.

  • Lossy compression throws away detail the eye is unlikely to miss. The file gets much smaller, and the discarded detail cannot be got back. JPG works this way.
  • Lossless compression packs the same pixels into less space. Unpacked, every pixel is exactly as it was. PNG works this way.

An SVG does neither. It records instructions: a circle here with this radius, a path through these points, filled with this colour. The program showing it draws those shapes afresh at whatever size is asked for. No stored detail runs out, so nothing blurs however far it is enlarged. Raster vs vector explains the two kinds of picture.

FormatWhat it storesCompression
JPGPixelsLossy
PNGPixelsLossless
GIFPixels, in up to 256 coloursLossless, after the colours are reduced
WebPPixelsEither, chosen when saving
SVGShapes, as textNone
SVGZThe same SVG textLossless (gzip)

Where quality can still be lost

The format loses nothing, but the steps around it can.

Tracing a picture into an SVG. Turning a PNG or JPG into shapes is an estimate of where the edges run. The result can be very close, but it is a new drawing, not a perfect copy of the pixels. See how to convert a picture to SVG.

A picture embedded in the SVG. An SVG can hold a JPG or PNG inside an <image> element. That part of the file is pixels and behaves like pixels: it blurs when enlarged, and a JPG inside keeps whatever its compression already threw away. The SVG viewer says when a file has a picture stored inside it, which shows at once whether a file is real shapes or a picture in a wrapper.

Rounding the numbers. Tools that make SVG files smaller shorten the coordinates, say from 47.262188 to 47.26. That is a loss in the strict sense, though with sensible settings it is far too small to see. Cut too hard, curves begin to wobble. The SVG optimizer on this site treats rounding as the one step that can move anything, lets you choose the decimal places, and compares the picture before and after pixel by pixel.

Simplifying paths. Some editors and tools reduce the number of points in a path. Fewer points make a smaller file and a slightly different curve.

Exporting from an editor. Effects that SVG cannot describe may be turned into embedded pictures on export, and text may be converted to outlines, which looks the same but can no longer be retyped.

Converting the SVG to PNG or JPG. This is where pixels come in. The picture is fixed at the size chosen, and a JPG adds lossy compression on top. Keep the SVG as the original and export pictures from it as needed.

SVG compression: what SVGZ is

Because an SVG is text, it compresses well with ordinary lossless compression. An SVGZ file is exactly that: an SVG compressed with gzip, usually given the ending .svgz. Unpacking it gives back the original file, byte for byte.

SVGSVGZ
ContentsText you can read and editThe same text, gzip-compressed
Opens in a text editorYesNo, not until unpacked
Picture qualityThe sameThe same
File sizeLargerSmaller, for all but tiny files
Accepted byNearly everything that reads SVGFewer programs

On the web, SVGZ is rarely needed now. Most hosts and content networks compress text files, SVG included, as they send them, and the browser unpacks them without anyone noticing. A plain .svg on the server gets the benefit with none of the trouble. An .svgz on a server only displays if the server sends it with the header Content-Encoding: gzip as well as the type image/svg+xml. Browsers generally will not draw an .svgz opened straight from a folder.

Inkscape opens .svgz files and can save them: the compressed types are in the list under File, Save As. Many other programs, cutting software among them, expect a plain .svg, so unpack an SVGZ before uploading it anywhere.

Converting between SVG and SVGZ

Any gzip tool does it. On a Mac or Linux computer, in the terminal:

gzip -c drawing.svg > drawing.svgz

And back again:

gzip -dc < drawing.svgz > drawing.svg

On Windows, a program such as 7-Zip can make and open gzip files. Rename the result so that it ends in .svgz, or after unpacking, in .svg. In Inkscape, open the .svgz and save it as Plain SVG.

To make a file smaller and keep it a normal .svg, optimise it instead: comments, editor data and spare digits are removed and the file still opens everywhere. The two can be combined, since an optimised file also compresses to less.

Common problems

What you seeCauseFix
An SVG looks blurry when enlargedIt contains an embedded picture, not shapesTrace the picture, or get the vector original
The SVG is sharp but a PNG made from it is blurryThe PNG was exported too smallExport again at a larger pixel size with SVG to PNG
An .svgz shows as gibberish or will not openThe program does not unpack gzipUnpack it to .svg first
An .svgz does not display on a websiteThe server is not sending Content-Encoding: gzipSet the header, or upload a plain .svg
Curves look lumpy after optimisingToo few decimal places were keptOptimise the original again with more
The SVGZ is bigger than the SVGThe file is tiny, and gzip adds a few bytes of its ownKeep the plain file

Questions

Is SVG the best quality format? For artwork made of shapes, such as logos, icons, lettering and cut files, yes: it is exact at every size. For photographs it is the wrong tool, and a JPG, PNG or WebP is the right one.

Does saving an SVG again and again lose quality? No. A JPG degrades a little each time it is edited and saved again. An SVG is rewritten as the same shapes. An editor may write the numbers with fewer digits, which is the rounding described above.

Does resizing an SVG lose quality? No. Only the numbers that set its size change.