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
Nothing needed to be removed from this file.
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.
| # | Element | id | Fill | Stroke | Stroke width | Edit |
|---|
Element
Colours in the drawing
No colours yet. Colours of fill, stroke, stop-color, flood-color, lighting-color and color are listed here.
| Colour | Used | New colour | Change |
|---|
Optimise
3 decimals move a point by at most 0.0005 units.
Read an SVG first. The optimised file appears here.
- Size of your file
- Size after optimising
- Saved
- Rounding
| Step | Changes | Size after the step (bytes) |
|---|
Changes, line by line
| Line before | Line after | Change | Text |
|---|
How to use the editor
- Choose Open an SVG file, paste the code into the box and choose Read the code, or choose Try an example.
- Check the list Removed for safety. It names every part of your file that the page took out before drawing it.
- 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.
- In Colours in the drawing, choose a new colour for a colour and choose Change: every place that uses it gets the new colour.
- 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.
- 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
onclickandonload, andxml:base; - links (
hrefandxlink:href) to other files or pages, andjavascript: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 adata: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
@importor 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"orx="0"on a rectangle, and emptyclass,style,idandtransformattributes. 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 insidedefs,symbol,marker,pattern,maskorclipPathand 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, andmatrix(1 0 0 1 5 6)is written astranslate(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
switchorclipPath, 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.