SVG Optimizer
Reduce SVG file size through conservative cleanup and reference checks with precision controls plus a local preview before downloading revised markup.{{ summaryTitle }}
{{ summaryLine }}
{{ sourceExportStatus }}
Compare both renderings before download. Each preview uses an image blob URL, so the SVG is never inserted as active page markup.
{{ computation.values.optimized_svg }}
The chart renderer is unavailable. Exact byte values remain available in the optimization ledger.
| Category | Measure | Value | Review note | Copy |
|---|---|---|---|---|
| {{ row.category }} | {{ row.label }} | {{ row.value }} | {{ row.note }} |
SVG files are XML documents that describe shapes, text, paint servers, reuse links, and accessibility text. Two drawings can render alike while carrying very different amounts of formatting, numeric detail, editor metadata, and identifiers. Removing that extra material can reduce transfer size and make the markup easier to inspect, but an aggressive rewrite can also break a gradient, a reused symbol, an animation target, external CSS, or an accessible name.
Safe optimization starts by separating changes that are usually structural from changes that depend on how the file will be used. Comments, an XML declaration, and formatting whitespace outside text-sensitive elements are often removable. Decimal rounding changes geometry, while deleting metadata, titles, descriptions, or apparently unused IDs can change editing, accessibility, or embedding behavior.
| Choice | Possible benefit | What can go wrong |
|---|---|---|
| Round numeric values | Shorter path, coordinate, and transform data. | Fine geometry may shift when too few decimal places are retained. |
| Remove metadata | Less non-rendered authoring data. | Round-trip information needed by an editor may be lost. |
| Remove unreferenced IDs | Shorter markup in a self-contained file. | External styles or scripts may still depend on those IDs. |
| Remove title and description | Fewer descriptive elements and related references. | The graphic may lose its accessible name or description. |
File size is only one success measure. The optimized SVG should remain well-formed, preserve every required internal reference, and look and behave correctly in the place where it will be published. Keep the source file until that review is complete.
How to Use This Tool:
Choose the preservation policy before treating a smaller byte count as a finished result.
- Paste SVG markup, drop an SVG or TXT file onto SVG source, or browse for an SVG file no larger than 1,048,576 bytes.
- Select Safe cleanup for reusable artwork. Use Compact cleanup only when the SVG is self-contained and outside CSS or scripts do not rely on unused IDs.
- Open Advanced when numeric precision, metadata, IDs, or title and description content need an explicit policy. Three decimal places and preservation of accessibility text are the neutral choices.
- Read any validation message before reviewing the output. Active elements, event attributes, external resources, unsafe URLs, malformed XML, duplicate IDs, and broken required references are rejected rather than rewritten.
- Compare the original and optimized previews, then check Byte comparison and the warnings in Optimization ledger before copying or downloading the revised SVG.
Interpreting Results:
A positive Savings value means the serialized output uses fewer UTF-8 bytes. Zero means no conservative reduction was available. A negative value is possible when deterministic serialization makes the source longer, so smaller output is not guaranteed.
- Review the actual preview, not only the percentage. Visual equality in one preview still cannot prove that an external stylesheet, script, or authoring application will behave the same.
- Check the remaining element, attribute, ID, and required-reference counts when a preservation choice removed structure.
- Treat every warning as a handoff check. Removed IDs and accessible text require review in the final embedding context.
Technical Details:
Conservative SVG cleanup is a parse, validate, transform, and revalidate process. The source must contain exactly one SVG root in the SVG namespace. Text inside text, text-path, style, title, and description elements keeps its significant whitespace, while formatting-only whitespace elsewhere can be removed.
Transformation Core:
| Stage | Operation | Preservation rule |
|---|---|---|
| Structural validation | Tokenize XML, match tags, count depth, elements, and attributes. | Require one SVG root, at most 5,000 elements, 30,000 attributes, and 128 nesting levels. |
| Safety validation | Reject active elements, event attributes, external resource links, unsafe CSS URLs, custom entities, and document type declarations. | Only internal fragment references such as #paint and url(#paint) are accepted. |
| Policy removal | Optionally remove metadata, title and description elements, and unreferenced IDs. | Referenced IDs are retained; matching ARIA references are cleaned only when their title or description target is removed. |
| Numeric normalization | Round numeric tokens in geometry, coordinate, opacity, transform, and related numeric attributes to 1–6 decimal places. | Non-finite tokens are left unchanged; negative zero becomes zero. |
| Serialization | Remove comments, the XML declaration, non-sensitive formatting whitespace, and empty class or style attributes. | The serialized result is parsed again before it is accepted. |
Rule Core:
Safe cleanup follows preservation-first defaults. Compact cleanup removes metadata and unreferenced IDs unless an advanced override preserves them. Title and description removal is always an explicit choice. A required internal reference with no matching ID, or a duplicate or invalid ID, stops the transformation.
Formula Core:
The reported reduction compares UTF-8 byte counts before and after serialization and rounds the percentage to two decimal places.
Boriginal and Boptimized are UTF-8 byte counts. For example, reducing 142 bytes to 104 bytes saves 38 bytes, or 26.76% after rounding.
Privacy and Safety Notes:
The SVG source is processed in the current browser session and is not uploaded or placed in a shareable URL. The optimizer also refuses active and external content before previewing it.
- Local processing does not make an unknown SVG trustworthy in every other viewer or publishing system.
- Compact cleanup cannot discover references that live outside the file.
- Removing title or description elements may reduce accessibility even when the visible drawing is unchanged.
References:
- Scalable Vector Graphics (SVG) 2, World Wide Web Consortium, Candidate Recommendation 4 October 2018.
- SVGO plugin documentation, SVGO.