How to Minify an SVG
Most SVGs that come out of a design tool are indented for humans and carry a comment or two. That is fine in a file on disk, but once the markup is pasted into a page, a stylesheet or a component it is just extra weight. This minifier turns it into one line and leaves the drawing alone.
Paste or open your SVG
Paste the markup into the editor, choose a .svg file, or drop one onto the editor area. Files up to 10 MB are accepted. Any well-formed SVG works, whether it came from Figma, Illustrator, Inkscape or an icon set. If the top element is not an <svg>, you get a message instead of output.
What gets removed, and what never does
- • Removed: comments, and the line breaks and indentation between tags
- • Tidied: extra spaces inside d, points, transform, viewBox and similar number lists
- • Kept as written: every number (no rounding), ids, colours, gradients and attribute values
- • Kept as written: text in <text>, <tspan>, <title> and <desc>, plus <style> and <script> content
Read the minified code
The one-line version appears below the preview as soon as the SVG is in the editor. Broken markup shows the parser message with its line and column instead. There is no button to press. Here is what an exported icon looks like before and after:
Before (281 bytes):
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
<!-- Exported from a design tool -->
<g fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="10"/>
<path d="M12 6 L12 12
L16 14"/>
</g>
</svg>After (210 bytes):
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><g fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="M12 6 L12 12 L16 14"/></g></svg>
Check the size and the preview
Compare the byte count of the original with the minified one and glance at the preview to confirm the drawing looks the same. How much you save depends on how airy the file was: the Sample drops from 530 to 381 bytes, while an SVG that is already compact may not change at all. For path rewriting or rounding coordinates, run the result through a tool like SVGOMG and check the drawing afterwards.
Copy or download
Copy the code straight into your HTML, CSS or component, or download it as minified.svg. A few places where a one-line SVG is handy:
- • HTML: an icon pasted straight into a template or a CMS field
- • CSS: a
background-image: url("data:image/svg+xml,...")value, or encode it as Base64 first - • React: markup you are about to turn into a component with SVG to JSX
- • Email: smaller inline markup in HTML newsletters
Want to see or edit the drawing first? Open it in the SVG Viewer. The SVG Optimizer runs the same safe clean-up when you are shrinking whole files rather than inline snippets.
Frequently Asked Questions
What exactly does the minifier take out?
Three things: XML comments, the line breaks and indentation sitting between tags, and runs of extra spaces inside list attributes such as d, points, transform and viewBox. Attribute values, ids, colours and every number are copied character for character. The clock icon in the example below goes from 281 to 210 bytes.
Why would I minify an SVG I only paste inline?
Inline SVG ends up inside your HTML, a CSS background-image data URI or a JSX component, and every line break and comment travels with each page view. A one-line version is also easier to drop into a string or a template without breaking the indentation of the file around it.
Can minifying break text inside the SVG?
Text is the one place where whitespace shows on screen, so it is left alone. Anything inside <text>, <tspan>, <textPath>, <title>, <desc>, <style>, <script> or <foreignObject>, and anything under xml:space="preserve", keeps its spaces and line breaks, including the single space between two tspans.
Are the byte counts real?
Yes, they are the UTF-8 size of the text in each box, measured after the change, so the number next to the output is the size of the file you download or copy. Short files that are already on one line can come out exactly the same size.
Why does my <?xml ?> line disappear?
The output starts at the <svg> element, which is what you want for inline use. Browsers do not need the XML declaration or a DOCTYPE. If you plan to open the file on its own, keep the xmlns attribute on the <svg> element; the minifier never removes it.
Is my SVG sent to a server?
No. The minifying runs in your browser and the file is not uploaded. Nothing is kept either: reload the page and the editor is empty again. The preview is drawn in a locked-down frame, so scripts or event handlers in a pasted SVG cannot run on this page.
Related Tools
SVG Viewer
View and preview SVG files online with instant rendering
SVG Editor
Edit and format SVG code with live preview and validation
SVG Optimizer
Optimize SVG files to reduce size and improve performance
XML Minifier
Minify and compress XML data
HTML Minifier
Minify and compress HTML code online, remove whitespace to reduce file size for better performance
JavaScript Minifier
Minify and compress JavaScript code online for production deployment and optimization