Code & Media

SVG Optimizer

Optimize an SVG and compare the result against the original, visually.

  • Draft kept in this tabYour draft is kept in this tab's session storage and cleared when the tab closes.
  • Runs in your browserProcessing happens in this page. No application server receives your input.
Load sample

SVG markup input

Optimized SVG output

Preview

Optimization details

Precision
2
Remove metadata
yes
Original size
0 B
Output size
0 B
Byte delta
0 B
Removed scripts
0
Removed event handlers
0
Execution
In-page

What this tool does

Removes redundant SVG markup, rounds numeric coordinates, strips active content (<script>, <foreignObject>, <iframe>, on* event handlers, and executable URLs), blocks external <use> and <image> network references, reports the UTF-8 byte delta, and renders a sanitized visual preview locally.

Optimization & sanitization rules

  • Valid SVG document: collapses redundant whitespace, comments, and empty tag pairs, rounds numeric attributes to the chosen precision, and reports a negative UTF-8 byteDelta.
  • SVG containing <script> or active elements: strips <script>, <foreignObject>, <iframe>, <object>, and <embed> from both optimized output and visual preview while counting removed scripts.
  • SVG containing on* event attributes or javascript:/vbscript:/data:text/html URLs: strips the attributes and counts removed event handlers (FR-CODE-5).
  • SVG whose optimized candidate is not smaller (with no security modifications): preserves the original markup with byteDelta: 0 (FR-CODE-4).
  • External <image href> and non-# references are removed from the isolated <img src="blob:..."> preview with the notice "External references were removed from the preview." (FR-SVG-1, FR-SVG-2, Binding Decision 3).
  • Non-SVG root elements return NotSvg; unclosed or mismatched tags return MalformedMarkup.

Operational limits & execution

Maximum input size: 4.0 MB and 100,000 elements (returns InputTooLarge above cap). Runs in-page below 1.0 MB and offloads to codegen.worker.ts at or above 1.0 MB with cooperative cancellation.

Worked example

Input:

<svg xmlns="http://www.w3.org/2000/svg"><script>alert(1)</script><rect/></svg>

Expected output:

<svg xmlns="http://www.w3.org/2000/svg"><rect/></svg>

Scope: this covers the page itself. Your browser, operating system, clipboard, downloads, extensions, and crash recovery may keep copies, and a compromised site origin would not be protected.