How to Clean and Minify SVG Markup in the Browser: Comments, Metadata and Editor Data
Learn exactly what the SVG Code Optimizer removes from pasted markup, including comments, metadata and Inkscape data, what it leaves untouched, and how to copy the cleaned result into your project.
SVG Code Optimizer
Introduction
SVG files exported from design tools often carry editor comments and indentation that add bytes without changing the drawing. The SVG Code Optimizer parses pasted markup with the browser's XML parser, removes comments, the XML prolog and DOCTYPE, metadata elements, Inkscape and Sodipodi editor data, empty groups and whitespace between tags, and shows the compact result side by side with the original. Everything runs in the browser as you type.
Step-by-Step Instructions
- Paste the vector markup into the Raw SVG Code Input box, replacing the sample circle.
- Watch the Clean Minified SVG panel update immediately; if the markup is not well-formed XML, an error explains that instead.
- Confirm that indentation and line breaks between tags have been collapsed so the markup sits on one line.
- Click Copy SVG to place the minified code on the clipboard.
- Paste the result into an inline svg element, a sprite file or a data URI.
Key Use Cases
- Inline Icons: Trim an exported icon before embedding it directly in HTML.
- Sprite Sheets: Clean several symbols before combining them into one sprite file.
- Email and CMS Fields: Collapse multi-line markup into a single line for editors that reject line breaks.
Frequently Asked Questions
What exactly does the optimizer remove?
It removes comments, processing instructions such as the <?xml ?> prolog, the DOCTYPE, <metadata> elements, elements and attributes in the Inkscape and Sodipodi namespaces, namespace declarations nothing uses any more, empty <defs> and <g> elements, and whitespace-only text between tags. Other attributes, element names, ids and path data are left exactly as they were.
Does it shorten path data or merge shapes like SVGO?
No. It cleans the document structure but does not rewrite geometry. Path coordinates and precision, transforms, colours and non-empty defs such as unused gradients stay in place, so files with heavy path data still benefit from a full optimiser like SVGO.
Can collapsing whitespace break my SVG?
Whitespace between shapes is not rendered, so the drawing is unaffected. Whitespace inside text, tspan, textPath, style, title and desc elements is kept, so words split across tspan elements stay separated. Markup that is not well-formed XML is reported as an error rather than altered.