Shrink an SVG file by removing comments and extra whitespace from its markup, right in your browser. The picture itself is not changed: the output is still a vector SVG at the same size, just written more tightly.
Drag and drop an SVG here, or
The markup must contain one <svg> root element. Anything you paste stays on your device.
Choose an SVG or paste markup, then press Compress SVG to see your result.
Please note: This tool only shrinks the markup text. It does not rasterize the SVG, it does not remove embedded images (images stored as data-URIs stay in the file), and it never executes scripts in the SVG: your markup is parsed as text and never added to the page. A heavily optimized SVG may shrink little, and that is reported honestly as a small byte saving, not hidden.
Private by design: your SVG is parsed and compressed entirely in your browser. It is never uploaded to any server.
How to compress svg online
If you need to compress svg files without installing any software, this free tool shrinks an SVG by tightening its markup, right inside your browser. Upload an .svg file or paste SVG markup, press “Compress SVG”, and download a smaller SVG that draws exactly the same picture at the same size. There is no sign-up, no watermark, and your file never leaves your device.
- Choose your SVG. Click the “Upload SVG file” tab and choose a .svg file, or click the “Paste SVG markup” tab and paste a complete SVG document. Files up to 25 MB are accepted.
- Press “Compress SVG”. The tool parses your SVG, removes XML comments, collapses whitespace between tags, trims the ends, and collapses runs of whitespace inside attribute values. It never removes attributes, ids, classes, or elements.
- Check the numbers. The results panel reports the original size in bytes, the compressed size in bytes, and the bytes saved. The compressed markup is also shown on the page so you can inspect it before downloading.
- Download your SVG. Press the download button to save the compressed file, named after your original file with “-compressed.svg” added, for example test-square-compressed.svg. A copy button copies the compressed markup to your clipboard.
Compression usually takes less than a second for a normal SVG. Because everything runs on your own computer or phone, you can compress as many SVG files as you like, and closing the tab removes every trace of your files.
What does “compress SVG” mean here?
SVG stands for Scalable Vector Graphics. Unlike JPG or PNG, an SVG is not a grid of pixels. It is a text document that describes shapes, paths, colors, and text with markup, and the browser draws the picture from those instructions. That text can be bloated: design tools often export SVGs with long comments, generous indentation, blank lines, and extra spaces inside attribute values, all of which make the file bigger without changing the picture at all.
Compressing an SVG in this tool means shrinking that text. Removing a comment does not change any shape. Collapsing the whitespace between two tags does not move anything. Collapsing extra spaces inside an attribute value does not change the value. The picture drawn from the compressed markup is the same picture, at the same intrinsic size, because nothing that affects drawing was touched.
This is deliberately conservative. Some SVG optimizers rewrite paths, round coordinates, remove ids, strip classes, or drop elements they judge unnecessary, and those changes can break styling, scripting, or animation that depends on the removed pieces. This tool does none of that. It only removes text that cannot affect the drawing, and it verifies the result before offering it, as described below.
What the tool changes, and what it never changes
The tool makes exactly four kinds of change to the markup text. First, it strips XML comments, the sections between <!– and –>, which are notes for humans and never affect drawing. Second, it collapses whitespace between tags, so a newline and indentation between a closing tag and the next opening tag becomes nothing. Third, it trims leading and trailing whitespace from the whole document. Fourth, it collapses runs of whitespace inside attribute values to a single space, and trims the ends of those values.
Everything else is left alone. Attributes are never removed, so width, height, viewBox, fill, id, and class attributes all survive exactly, apart from the whitespace collapsing inside their values. Elements are never removed, so no path, rect, circle, group, or text element disappears. Text content inside elements is never rewritten, apart from the whitespace between tags, so labels and titles in the SVG keep their wording. The tool also never claims a specific percentage saving, because the saving depends entirely on how bloated the input was: a file full of comments shrinks a lot, and a file that is already tight shrinks little, and both outcomes are reported honestly as byte counts.
A worked example makes this concrete. The test file used for this tool is a 200 by 200 SVG containing a blue rectangle, a red circle, and a text label. With added comments and extra whitespace, the file was larger than the clean original. After compression, the comments were gone, the whitespace between tags was collapsed, the file was smaller, it still parsed as SVG, it still reported a 200 by 200 intrinsic size, and it still rasterized to 200 by 200 pixels. That is the whole promise of the tool, and it is verified on every run by the safety check in the next section.
The safety check: no download unless the output still parses at the same size
After minifying, the tool re-parses the compressed markup with the browser’s DOM parser as SVG, and it only offers a download when three conditions all hold. First, the re-parse must succeed with no parser error. Second, the output must contain an <svg> root element. Third, the intrinsic size of the output, read from its width and height attributes or from its viewBox, must be identical to the intrinsic size of the input.
If any of those conditions fails, the tool shows an honest error and offers no download at all. It never offers a broken or resized file and asks you to trust it. This check runs on every compression, not just in testing, so a pathological input that minifies badly cannot slip a wrong file past you.
The same strictness applies to the input. Markup without an <svg> root element is rejected with “The pasted markup does not contain an <svg> root element,” and an SVG with neither width and height nor a viewBox is rejected as having no intrinsic size, because without a real size the tool cannot verify that the output matches the input. Those rejections are not bugs: they are the tool refusing to guess.
What this tool does not do
Four limits deserve plain statements, because each one is a place where a careless tool could mislead you. First, this tool does not rasterize. The output is still an SVG file, a vector document, not a JPG or PNG image. If you need a raster image, use our SVG to JPG converter instead.
Second, it does not remove embedded images. An SVG can contain an image stored as a data-URI, a long base64 string inside the markup, and that string stays in the compressed file, because removing it would change the picture. An SVG dominated by an embedded image will therefore shrink little, and the byte counts will show that honestly.
Third, it does not execute scripts. Your markup is parsed as text by the DOM parser and is never inserted into the page, so any script inside an SVG is never run by this tool. The compressed output still contains whatever the input contained, apart from the four safe text changes, so you should still only use SVGs from sources you trust in your own projects.
Fourth, it does not optimize paths, round coordinates, or remove supposedly unused definitions. Those techniques can shrink an SVG further, but they can also break the file in subtle ways. If you need aggressive optimization and you understand those risks, a dedicated optimizer is the right choice. This tool is the safe, conservative option: smaller file, same picture, nothing removed that could matter.
Why SVG files get bloated in the first place
Design tools export SVGs for editing, not for the web. An editor keeps generous indentation so a human can read the file, adds comments recording the export settings or the layer names, and writes attribute values with extra spaces for readability. Some tools also write the same default attributes on every element, and write coordinates with more decimal places than any screen can show. All of that is useful while you are editing, and all of it is dead weight once the file is published on a website.
That dead weight has a real cost. SVG files are often inlined into web pages or loaded as images, and every extra byte is a byte the visitor’s browser must download and parse. For a single small icon the saving is tiny, but for a site that uses dozens of SVG illustrations, or for a large diagram, the total saving is real. Compressing before publishing is a simple, safe step in preparing web graphics, and it pairs naturally with Compress PNG and Compress WebP for raster images.
It is also worth knowing when compression will not help much. An SVG that is already minified, with no comments and no extra whitespace, will come out almost the same size, and the tool will report a small byte saving rather than inventing a larger one. An SVG that is mostly an embedded image will shrink little for the reason given above. In both cases the honest byte counts tell you exactly what happened, and you lose nothing by trying.
File size limits and private in-browser compression
Files up to 25 MB are accepted. For uploaded files the size is checked before the file is even read, so an oversized file is rejected instantly with the message “File is too large. Maximum size is 25 MB.” Pasted markup is checked the same way, against its UTF-8 byte size. This comfortably covers SVG files from typical design tools.
Privacy is structural, not a promise. Your SVG is read, parsed, and compressed entirely inside your own browser using standard web technology. The file is never uploaded to Pixel File or to any third party, nothing is stored on a server, and no account is needed. Closing the tab discards everything.
Common uses for SVG compression
Website icons and logos are the most common case. A logo exported from a design tool often carries comments and indentation that add bytes without adding anything to the drawing. Compressing it before publishing gives you the same logo in a smaller file, which loads faster for every visitor.
Illustrations and diagrams are another frequent use. A detailed illustration can run to tens of kilobytes of markup, much of it whitespace and comments from the editor. A conservative compression pass trims that dead weight while keeping every shape, id, and class intact, so the illustration still works with your site’s styling and any interactivity that depends on those ids.
Icons shipped inside web pages benefit too. When an SVG is pasted directly into page markup, its bytes count toward the page size on every visit. Tightening the markup before pasting keeps the page lean without changing the icon. And when you are preparing a set of SVGs for a project, running each one through this tool first is a quick hygiene step that costs nothing and can only shrink the files.
Frequently asked questions
Is this SVG compressor free to use?
Yes. The compressor is completely free with no sign-up, no watermark, and no limit on how many SVG files you compress. It runs entirely in your browser, so there are no server costs passed on to you.
What exactly does the compressor change in my SVG?
Only four text-level changes: it strips XML comments, collapses whitespace between tags, trims leading and trailing whitespace, and collapses runs of whitespace inside attribute values to a single space. It never removes attributes, ids, classes, or elements, and it never rewrites paths or coordinates.
How do I know the compressed SVG still draws the same picture?
The tool re-parses the compressed markup and only offers a download when the re-parse succeeds, an <svg> root is present, and the intrinsic size is identical to the input’s size. If any of those checks fails, it shows an error and offers no download. The compressed markup is also shown on the page so you can inspect it before downloading.
Why did my SVG shrink so little?
The saving depends on how bloated the input was. An SVG that is already minified has little dead weight to remove, and an SVG dominated by an embedded image keeps that image, because removing it would change the picture. The tool reports the original bytes, the compressed bytes, and the bytes saved, so you can see exactly what happened. It never claims a percentage saving.
Does the tool convert my SVG to JPG or PNG?
No. The output is still an SVG file, a vector document at the same size. This tool never rasterizes. If you need a raster image, use the SVG to JPG converter, which draws the SVG onto a canvas and exports a JPG.
Does the tool run scripts inside my SVG?
No. Your markup is parsed as text and is never inserted into the page, so scripts inside an SVG are never executed by this tool. The compressed output still contains whatever the input contained, apart from the four safe text changes, so only use SVGs from sources you trust in your own projects.
Are my SVG files uploaded to a server, and is there a size limit?
No. Your SVG is parsed and compressed entirely inside your browser and is never uploaded, stored, or shared. Files up to 25 MB are accepted, and the size is checked before reading begins. Closing the tab removes all traces of your files.
More free image tools
Pixel File offers a full set of free tools that run in your browser. SVG to JPG turns a vector SVG into a JPG image, Compress PNG shrinks PNG files, Compress WebP shrinks WebP files, Compress Image handles general image compression, and Image to PDF bundles pictures into a PDF document. Every tool is free, private, and needs no sign-up.
References
- Wikipedia: SVG — The SVG format explained
- Wikipedia: Image compression — How image compression works