Export an icon from a vector editor, open the file as text, and you may have to scroll before you reach the picture. The top of the file is filled with material that has nothing to do with what the icon looks like: an editor comment, a metadata block, elements named after the program, and groups that contain nothing. An SVG optimizer exists to remove exactly that material, and nothing else.

This guide walks through the removal list item by item: what each piece of markup is, why the editor put it there, and why deleting it cannot change the drawing. It uses the free SVG Code Optimizer on Ovatly as the reference, because that tool shows its working, listing afterwards which rules fired.

Contents

  • Quick answer
  • Comments
  • Editor leftovers
  • Metadata blocks
  • Empty groups
  • Respelled, not removed: hex colors and whitespace
  • What is never removed
  • See the removals yourself
  • Worked example: one export, five removals
  • Limitations and honest tradeoffs
  • Common mistakes
  • FAQs
  • Conclusion
  • References

Quick answer

The SVG Code Optimizer removes five kinds of material: XML comments, editor leftovers (elements from the sodipodi and inkscape namespaces, and metadata blocks), empty groups, and stray whitespace, and it shortens hex colors such as #ffffff to #fff. It keeps the XML declaration unless you choose otherwise. It never touches path data, shapes, text or attribute values, and the result panel lists which rules fired, so you can see what your file lost.

Comments

Editors write XML comments into the file: a note about the program, the version, or who exported it. A comment looks like this:

<!-- Created with an SVG editor -->

Comments are instructions to nobody. Browsers skip them completely when rendering. They exist so a human opening the file later knows where it came from. In a shipped file that knowledge costs bytes on every download and buys nothing, so comments are the first and least controversial removal on the list.

Editor leftovers

When Inkscape saves a file, it records its own working state in elements from its own namespaces, such as a sodipodi:namedview element holding window and grid settings, and inkscape attributes scattered through the document. Other editors do the same in their own dialects. This material describes the editing session: which tools were open and how the canvas was set up.

None of it is part of the picture: browsers ignore these elements because they are not drawing instructions. Removing them has one real cost: the cleaned file no longer carries those editor settings, so it is a delivery copy, not a project file. Keep the original for editing, ship the cleaned one.

Metadata blocks

A metadata element holds document information: titles, descriptions, licensing notes and similar records about the file, not pixels in it. Like comments, it renders nothing. Unlike comments, it can occasionally be information you care about, such as a license statement meant to travel with the artwork. That is why the rule is a tick box rather than silent behaviour: if the metadata matters to you, leave the rule off; if it is the usual auto-generated block, removing it is pure saving.

Empty groups

A g element groups shapes together. During editing, groups get emptied as layers are rearranged or deleted, and the empty shells stay behind. An empty group draws nothing and affects nothing, but its tags still take space, and nested empty groups stack up in a heavily edited file. Dropping them is the structural equivalent of removing comments: the markup described an organisation that no longer exists.

Respelled, not removed: hex colors and whitespace

Two rules shrink the file without deleting any content at all.

Hex colors are shortened where a six-digit value can be written in three digits with no change in color: #ffffff becomes #fff. The fill or stroke is the identical color; only its spelling gets shorter.

Whitespace is collapsed rather than deleted outright. Indentation and blank lines between tags aid human readers, and the file keeps the minimum separation the markup needs. What goes is the surplus: the deep indentation ladders and empty lines an editor leaves behind. One honest exception: whitespace inside a style block can be code, so animated or scripted files deserve a careful look at the preview before you trust the output.

One item is kept by default: the XML declaration. Standalone files opened directly by other software sometimes rely on it; if your SVG will live inline in HTML, tick that rule too and save the last few bytes.

What is never removed

The other half of the story is what the tool refuses to touch: path data, shapes, text and attribute values are never rewritten. The drawing's geometry lives in those places, so leaving them alone is what guarantees the picture cannot change shape, move or lose detail.

This is where the tool parts company with a full minifier such as SVGO: no ID renaming, no path merging, no rounding of coordinates. Those techniques remove more bytes by altering the drawing's data. This tool stops at the markup around the drawing, and the fired-rules list is the complete account of what changed.

See the removals yourself

  1. Open the SVG Code Optimizer and paste your SVG code, or load the .svg file.
  2. Check the ticked rules: the defaults cover comments, editor leftovers, empty groups, hex shortening and whitespace, with the XML declaration kept.
  3. Press Optimize SVG, then read the result panel: the rules that fired, both sizes and the saving percentage.
  4. Compare the previews: they should be identical. Then download or copy the cleaned code, keeping your original as the editable source.

Worked example: one export, five removals

Take an exported icon of 393 bytes. It contains an XML comment, a metadata block, a sodipodi:namedview element, one empty group and a rectangle filled with #ffffff. Running the default rules removes the comment, the editor leftover and the metadata, drops the empty group, collapses the whitespace and respells the fill as #fff. The file comes out at 187 bytes, a 52.4 percent saving, and the result panel lists the five rules that fired.

The rectangle, the only actual picture in the file, lost nothing.

Limitations and honest tradeoffs

The removal list is deliberately short, so a hand-written SVG may contain almost nothing to remove, and the saving will be small. That is the tool working correctly, not failing. The tool also cannot read your intentions: it cannot tell a metadata block you want to keep from one you do not, which is why the rules are yours to tick. For animated or scripted files, the whitespace caution applies in full: compare the preview, keep the original either way.

Common mistakes

  • Expecting the optimizer to shrink the drawing. It removes markup around the picture; long path data stays as it was.
  • Deleting the original export. The cleaned file lost its editor settings by design. Ship the copy, archive the source.
  • Assuming an unlisted rule still ran. If a rule is not in the result panel's list, it changed nothing in your file.
  • Removing metadata you meant to publish. License or credit blocks live in metadata. Check before you tick.
  • Judging the tool by the percentage alone. The saving measures how much baggage your export carried, not the quality of the cleanup.

FAQs

Does the optimizer delete any part of the drawing itself? No. It removes markup around the drawing: comments, editor leftovers, metadata, empty groups and spare whitespace. Path data, shapes, text and attribute values are never rewritten, so no line, curve or letter is deleted.

What are editor leftovers in an SVG file? They are elements the editing program added for its own use, such as elements in the sodipodi and inkscape namespaces, plus metadata blocks recording the editing session and document settings. Browsers ignore them when rendering, so they only add weight.

If browsers ignore comments and whitespace, why remove them? Because ignoring happens after downloading. Every byte of comment and indentation travels with the file on every page view, so removing it shrinks the file even though the picture never depended on it.

Does the optimizer remove the XML declaration? Not by default. The declaration is kept unless you choose otherwise, because standalone .svg files opened directly by other software sometimes rely on it. If the SVG will be pasted inline into HTML, you can tick that rule too.

How do I know exactly what was removed from my file? The result panel lists the rules that actually fired, with the before and after sizes and the saving percentage. A rule that is not listed changed nothing in your file, and the previews let you confirm the picture is identical.

Conclusion

An SVG optimizer removes the record of the editing session, not the artwork: comments, editor leftovers, metadata, empty groups and surplus whitespace, with colors respelled shorter and the declaration kept by default. The SVG Code Optimizer shows the list of fired rules for every file, so the removals are never a mystery. If you want to know what those removals add up to on a real logo, our companion guide on how much smaller optimization can make a logo file works through the numbers. For more guides in this series, see our File and Data Conversion guides.

References