Toolvito

Works on this device

SVG Editor & Optimizer

Open or paste an SVG file. Change its elements, attributes, text and colours in a table or in the code, and make the file smaller with optimising steps that you switch on and off. Scripts and links to other files are removed first. Everything runs in this browser.

Your SVG

A file of at most 1 MB of text, in UTF-8 or UTF-16. It is read in this browser and is not uploaded.

Paste the code of an SVG file, or change the code here, then choose Read the code. After a change in the table below, the code is written again from the edited drawing.

Removed for safety

Scripts, event handlers, foreignObject, links to other files and outside resources are always removed before the file is drawn, edited or saved.

Edit elements and colours

Read an SVG first. Its elements are listed here.

Colours in the drawing

No colours yet. Colours of fill, stroke, stop-color, flood-color, lighting-color and color are listed here.

Optimise

Steps to use

Comments that start with ! are kept, because they often hold a licence.

The <metadata> element and the <?xml ...?> line. Titles and descriptions stay, because they name the drawing for screen readers.

Elements and attributes that Inkscape, Illustrator, Sketch, Figma and other programs keep for themselves. Browsers do not draw them.

Such as fill-opacity="1" or stroke="none". A value that children take over is removed only when it is safe.

Such as translate(0) or two moves in a row. A single move of a shape goes into its coordinates when nothing depends on it.

This moves points a little: at most half of the last decimal you keep. The result says the largest change. Path data is rounded only together with the next step.

Relative or absolute numbers, whichever is shorter, H and V for straight lines, and no repeated command letters. The shape stays exactly the same.

g and defs elements with nothing inside them.

Their content stays where it was.

Such as xmlns:xlink when no xlink:href is left.

Not inside text, titles and style sheets, where spaces are part of the drawing.

3 decimals move a point by at most 0.0005 units.

Read an SVG first. The optimised file appears here.

How to use the editor

  1. Choose Open an SVG file, paste the code into the box and choose Read the code, or choose Try an example.
  2. Check the list Removed for safety. It names every part of your file that the page took out before drawing it.
  3. In Edit elements and colours, choose Edit in the row of an element. Change its fill and stroke, its text, or any attribute, or remove it. A change is used when you leave the box. Undo and Redo step back and forward.
  4. In Colours in the drawing, choose a new colour for a colour and choose Change: every place that uses it gets the new colour.
  5. In Optimise, switch the steps on and off and choose how many decimals to keep. The sizes, the two previews, the steps table and the changes line by line follow at once.
  6. Choose Download SVG or Copy code.

What the safety cleaning removes

An SVG file can hold code and links that run or load when the file is opened. This page reads your file as text and never puts it into the page. Before it draws or saves anything, it keeps only what is on its list of drawing elements and removes:

  • script elements, foreignObject elements (they can hold web page content), elements of HTML and of other XML vocabularies, the DOCTYPE and processing instructions such as <?xml-stylesheet?>;
  • event handler attributes that start with on, such as onclick and onload, and xml:base;
  • links (href and xlink:href) to other files or pages, and javascript: links. A link to an element of the same file, such as #gradient1, stays, and so does a PNG, JPEG, GIF or WebP picture held inside an image as a data: address;
  • url() in style and paint attributes when it points outside the file, style text with a backslash (it could hide a url()), and style elements with @import or an outside url();
  • animations that change a link.

The content of <metadata> and the data of drawing programs (Inkscape, Illustrator and others) stay until you remove them with an optimising step, because they are never drawn. Then your browser reads the cleaned file again with its own XML reader (DOMParser, as image/svg+xml, in a document that is never shown) and checks once more for scripts, event handlers and links that leave the file. Previews are pictures made from the cleaned file, so nothing in it can run on this page.

The optimising steps

The steps run in this order. Every step keeps the drawing exactly the same, except rounding, which says how far it moved a point.

  • Remove comments: comments that start with ! stay, because they often hold a licence.
  • Remove metadata and the XML declaration: titles and descriptions stay, because they name the drawing for screen readers.
  • Remove editor data: elements, attributes and namespace declarations of Inkscape, Sodipodi, Illustrator, Sketch, Figma, Affinity, Visio and of file metadata (RDF, Dublin Core, Creative Commons).
  • Remove attributes at their default values: such as fill-opacity="1", stroke="none", stroke-width="1" or x="0" on a rectangle, and empty class, style, id and transform attributes. A value that children take over, such as fill, is removed only when no element around it sets the same property, the file has no <style> element, and the element is not inside defs, symbol, marker, pattern, mask or clipPath and is not used again by <use>.
  • Collapse transforms when the result is exact: translate(0) and other transforms that change nothing are removed, two moves in a row become one, and matrix(1 0 0 1 5 6) is written as translate(5 6). A single move of a shape goes into its coordinates when nothing depends on its coordinate system (no id, no url(), no <style> element).
  • Round coordinates of shapes: numbers of path data (only together with the next step), points, positions and sizes of rectangles, circles, ellipses and lines are rounded to the decimals you choose, a half away from zero. Each number moves by at most half of the last decimal kept, and the result shows the largest change. This is the only step that can change the drawing.
  • Shorten path data and lists of points: each piece of a path is written with absolute or relative numbers, whichever is shorter; straight lines along an axis as H or V; curves as S or T when their first control point is the reflection that S or T stands for; repeated command letters are left out, and so are zeros before a decimal point. The numbers are added exactly as decimals, so the path is the very same path.
  • Remove empty groups, remove groups that have no attributes (their content stays; not inside switch or clipPath, and not when the file has a <style> element), remove namespace declarations that nothing uses, and remove spaces and line breaks between elements (not inside text, titles and style sheets).

Worked example

The example drawing is 1,547 bytes. With every step on and 3 decimals kept it becomes 474 bytes, so 1,073 bytes (69.4%) are saved.

The roof and walls M 60.000000 150.000000 L 60.000000 90.000000 L 120.000000 50.000000 L 180.000000 90.000000 L 180.000000 150.000000 Z become M60 150V90l60-40 60 40v60z: the first line goes straight up, so it is V90, and the next two are shorter as relative moves.

The door has transform="translate(10 20)" with x = 90 and y = 80. The move goes into its coordinates: x = 100 and y = 100. Its width 40.0004 is rounded to 40, a change of 0.0004. Three numbers are rounded in all; the largest change is 0.000456, where 40.123456 in the curve of the grass becomes 40.123.

Limits you should know

  • Files of up to 1,048,576 characters (1 MB) and 20,000 elements.
  • This is not a drawing program: you cannot draw new shapes with the mouse. You can add elements in the code. To draw a path with points and handles, use the Bezier Path Editor.
  • The file is written again by this page: quotes become double quotes, character references become plain characters, and the file is saved as UTF-8.
  • The optimiser looks only at this file. If you place the SVG inside a web page whose style sheet sets fill, stroke or other properties, check the result there.
  • Colour changes work on fill, stroke, stop-color, flood-color, lighting-color and color in attributes and style attributes, not inside <style> elements.
  • Previews stop animations unless you tick Play animations in the previews. An animated GIF inside an SVG may still move.
  • Rounding can make very small shapes change. Choose more decimals, or switch rounding off, when you need every digit.

Related tools