Design tool

SVG Optimizer

Paste or choose an SVG to create an optimized copy.

Runs in your browser. No upload.

Values are processed locally in this browser.

Result

—

About this tool

SVG Optimizer made simple.

The local optimizer rejects scripts, foreign content and external references rather than trying to make active SVG safe. Review the output before publishing.

Guide

Using SVG Optimizer

The SVG Optimizer makes a smaller copy of an SVG file by taking out comments and extra white space. You paste the markup or choose a file, and you get cleaned text plus a download. It does not redraw, merge or round any shapes, and it refuses SVGs that contain scripts or links to other sites.

How to use it

  1. Paste the full SVG markup into the box, or choose an SVG file. The text must start with the svg tag, with an optional XML line before it.
  2. Press the button to run the cleanup. If the file has active or external content, the tool stops and shows a message instead.
  3. Read the optimized text and compare it with your original. Then download it as usefulverse-optimized.svg.

Worked examples

Removing a comment and spaces

You enter
Svg
<svg width="10" height="10"> <!-- background --> <rect width="10" height="10" fill="#fff" /> </svg>
You get
Svg
<svg width="10" height="10"><rect width="10" height="10" fill="#fff"/></svg>
Characters before
109
Characters after
76

The comment goes, line breaks and spaces between tags go, double spaces inside tags shrink to one, and the space before a closing slash goes too. The shapes are untouched.

Run through the tool’s own code.

A script is rejected

You enter
Svg
<svg><script>alert(1)</script></svg>
You get
Message
This SVG contains active or external content and was not processed.

Script tags, event attributes such as onload, links to outside addresses and foreignObject make the tool stop. It does not try to clean them, so nothing is returned.

Run through the tool’s own code.

A caution about preserved spaces

You enter
Svg
<svg><text xml:space="preserve">a b</text></svg>
You get
Svg
<svg><text xml:space="preserve">a b</text></svg>

The tool collapses runs of spaces everywhere, also inside text. If a file relies on spaces that were meant to stay, the optimized copy can look different. Compare before you use it.

Run through the tool’s own code.

When it helps

  • Trim comments and indentation from an SVG icon before adding it to a web page.
  • Make inline SVG in HTML a little shorter.
  • Check quickly whether an SVG holds scripts or outside links.

Limits to keep in mind

  • It only removes comments and extra white space. It does not merge paths, shorten numbers, remove unused ids or compress like a full optimizer, so the savings are small.
  • Input must be a complete SVG document. Anything else, such as HTML or a fragment, returns the message to paste a complete SVG document.
  • The safety check is a simple text match. It may also reject harmless text that looks like an attribute, such as a word starting with on followed by an equals sign, so review any file it blocks.

Tips

  • Keep your original file and compare the result in a browser before you replace it.
  • Avoid xml:space preserve text if you plan to optimize, or check that text by eye afterwards.
  • Gzip on your server will usually shrink SVG much more than this tool, so use both.

Common questions

About SVG Optimizer.

What does the SVG Optimizer remove?

It removes comments, line breaks and tabs, extra spaces, spaces between tags and the space before a closing bracket. The drawing instructions and values are left as written.

Will my SVG look the same afterwards?

Usually yes, because only comments and white space change. The exception is text that depends on exact spacing, so open both files side by side before you replace the original.

Why was my SVG not processed?

The tool refuses SVGs with script tags, on-event attributes, links starting with http, https or two slashes, javascript links or foreignObject. Such files can be unsafe, so it stops instead of trying to repair them.

Does it work with a file as well as pasted text?

Yes. A chosen file is read only when the text box is empty. If the box already holds text, that text is used and the file is ignored, so clear the box first.

Is my SVG uploaded to a server?

No. The cleanup runs inside your browser on the text you give it. The file you download is made on your device, so nothing is sent away.

How much smaller will my file be?

It depends on the file. A hand-written SVG full of comments and indentation can shrink a lot, while a file from a design tool often shrinks only a little, as most of its size is path data.

How do I use SVG optimizer?

Paste or choose an SVG to create an optimized copy.

Is my data uploaded to a server?

No. This tool runs locally in your browser. Your input is not uploaded.