What is an SVG minifier?
An SVG minifier shrinks SVG code by removing the parts that do not affect how it looks: comments, line breaks, and extra spaces. Paste in an SVG exported from a design tool and you get back the same image in fewer bytes. The default SVG here is 135 characters, and minifying saves 15.6% of it.
SVG files from design tools are verbose. They carry editor comments, indentation on every line, and spaces that exist only to make the file readable in an editor. A browser does not need any of that — it reads the tags and the attributes, and the whitespace between them is ignored. Removing it makes the file smaller without changing the image.
This tool is different from the code minifier on this site, which handles JavaScript, CSS, and JSON. SVG is XML, and its minification is about whitespace and comments, not about renaming variables or removing semicolons. Use this tool for icons and illustrations, and the code minifier for scripts and styles.
How SVG minification works
The minifier runs four passes over the text. First it removes comments — anything between <!-- and --> — because comments never affect rendering. The default SVG has one comment, "icon", which is removed entirely.
Second, it removes whitespace between tags: the sequence ">" followed by spaces and newlines followed by "<" becomes "><". That is the biggest saving in a file from a design tool, where every tag sits on its own indented line. Third, it collapses runs of two or more spaces inside tags to a single space, so an attribute list with wide spacing becomes tight.
Fourth, it removes the space before /> and before >, and trims the ends of the file. What is left is the same SVG with the same tags and attributes, in 114 characters instead of 135 — a saving of 15.6%. The image renders identically, because nothing that affects rendering was touched.
What gets removed — and what does not
Comments are removed, because they are notes for humans, not instructions for the browser. A comment that says "icon" or "exported from Figma" has no effect on the image, and removing it is always safe.
Whitespace between tags is removed, because XML ignores it there. The newline and the indentation between </circle> and </svg> do not change the image — they only make the file readable in an editor. Inside a text element, whitespace is different: spaces inside <text> are part of the content, and this minifier does not collapse them below a single space.
What is not removed is anything that changes the image: attributes, values, and structure. The width, height, and fill of the default SVG are all kept exactly, and the circle's position and radius are untouched. A minifier that removed attributes would be a different tool — and a dangerous one, because it could change the image.
Comments are the first thing removed, and they are the safest to remove, because a comment in SVG is only a note for the author — it never affects the picture. An exported icon often carries a comment with the name of the program that made it, the date, and a licence line, and none of that is needed to draw the icon. The minifier strips every comment, which is usually the largest single saving in a file that was exported rather than written by hand. The licence line is the exception: if the licence requires the comment to stay, keep the file unminified or re-add the comment after.
A worked example: an exported icon
Take the default SVG: an svg element 100 by 100, a comment, and a red circle of radius 40 at the centre. It is 135 characters, spread over four lines with indentation. Minify it and you get one line of 114 characters: the comment is gone, the line breaks are gone, and the space before /> is gone.
The saving is 15.6%. For one icon that is a small saving, but a page with twenty icons saves twenty times as much — and inline SVG is often repeated on every page, so the saving multiplies across a whole site. That is why minification matters even for small files.
Try a larger SVG to see the effect grow: an icon with ten elements and a comment on every line can lose 30% or more, because the indentation alone is a large share of the file. The structure stays the same, so the image is identical — only the file is smaller.
Who uses an SVG minifier, and why
Web developers are the main users. Inline SVG icons are pasted into HTML, and a minified icon keeps the HTML file small and readable. An icon set with dozens of icons saves kilobytes across a site, which matters for loading time on slow connections.
Designers are the second group. An SVG exported from Figma, Illustrator, or Inkscape carries the editor's formatting, and minifying it before handing it to a developer gives them a clean file to work with. It is the last step of the export workflow.
Anyone embedding SVG in a page is a third group. A logo, a chart, or a diagram pasted into a blog post or a README should be as small as possible, because the reader downloads it with the page. A code minifier handles the scripts and styles on the same page.
Icon designers are a third group. An icon set is dozens of small SVG files, and each one is exported with whitespace, comments, and precision the drawing never needed. The minifier is the last step before the icons ship: run each file through it, and the set is smaller, faster to download, and no different to look at. The saving per icon is small, but a set of a hundred icons adds up, and a page that loads a hundred icons notices the difference.
SVG minifier vs code minifier
An SVG minifier works on XML; a code minifier works on JavaScript, CSS, and JSON. The code minifier on this site removes whitespace and comments from code, and can rename variables in JavaScript — which SVG has none of. The two tools share the idea — remove what does not affect the result — but the rules are different for each language. A CSS minifier handles stylesheets and a JS minifier handles scripts.
SVG minification is safer than JavaScript minification, because SVG has no variables to rename and no logic to break. The only risk is whitespace inside text elements, and this tool collapses it to a single space rather than removing it, so text keeps its spacing.
Both tools run in the browser and never upload your code. Use this one for icons and illustrations, and the code minifier for the scripts and styles that sit next to them on the page.
An SVG minifier is not a code minifier, and the distinction matters when the file is JavaScript or CSS rather than SVG. A code minifier renames variables and removes semicolons, which is safe for code but would break an SVG, because an SVG has no variables to rename. An SVG minifier only removes whitespace and comments and collapses spaces, which is safe for XML but would be a weak minification for code. Use each tool on the file type it was built for — the two tools do different jobs on different languages.
Common SVG minification mistakes
The first mistake is minifying by hand. Deleting line breaks by hand is slow and error-prone, and it is easy to delete a space that matters — such as the space between two attributes. Let the tool do it, and check the result renders the same before you ship it.
Second: removing attributes to save space. The width, height, and viewBox attributes matter, and removing them changes how the SVG scales. This tool never removes attributes, which is why its savings are smaller than a full optimiser's — and safer.
Third: minifying an SVG that contains text without checking it. Whitespace inside a <text> element is content, and collapsing it changes the spacing of the words. This tool collapses runs of spaces to one, which is safe for ordinary text, but check any SVG with carefully spaced text after minifying.
Fourth: expecting a large saving from an already-small file. A one-line SVG with no comments has almost nothing to remove, so the saving is near zero. Minification pays off on files from design tools, not on files that are already tight.
A second mistake is minifying an SVG that other code refers to by id. A gradient, a clip path, or a symbol that is used elsewhere in the page is found by its id, and the minifier keeps ids exactly as they are — it does not rename them, because renaming would break the reference. The danger is the opposite: two SVGs pasted into the same page with the same id will clash, and the second one will use the first one's gradient. The minifier cannot fix that, because the clash is in the page, not in the file. Give each SVG unique ids before minifying if the page holds more than one.
How to use this SVG minifier
Paste your SVG into the box — the default is 135 characters, and minifying saves 15.6%. The minified SVG appears instantly in the box below, with the original size, the minified size, and the percentage saved above it.
To copy the result, use the Copy button next to the output box, then paste it into your page. Check that the image renders the same — it should, because only comments and whitespace were removed.
Everything runs in your browser. No sign-up, no account, no data sent anywhere — your SVG never leaves your device. It works offline once the page has loaded.
Paste the SVG, press minify, and read the result before you copy it. The output shows the original size, the minified size, and the saving as a percentage, which is the number that tells you whether the minification was worth doing — an icon that went from 135 characters to 114 saved about a sixth of its size, and a large illustration can save far more. Check that the picture still renders by pasting the minified SVG into a page or an image viewer; if it renders, the minification was safe.