Skip to content

Cleaning up SVG code

This article is part of SVG clean up article.

When a designer exports icon from an editor, often SVG contains a lot of extra code that is not needed to display an icon.

Bad icon example

The following SVG was generated with popular Inkscape software:

svg<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "">
<svg version="1.1"
    id="svg2" xmlns:dc="" xmlns:cc="" xmlns:rdf="" xmlns:svg="" xmlns:sodipodi="" xmlns:inkscape="" sodipodi:docname="cloud.svg" inkscape:version="0.48.4 r9939"
    xmlns="" xmlns:xlink="" x="0px" y="0px" width="1200px" height="1200px"
    viewBox="0 0 1200 1200" enable-background="new 0 0 1200 1200" xml:space="preserve">

<sodipodi:namedview  inkscape:cy="448" inkscape:cx="-67.796606" inkscape:zoom="0.26339286" showgrid="false" id="namedview3175" guidetolerance="10" gridtolerance="10" objecttolerance="10" borderopacity="1" bordercolor="#666666" pagecolor="#ffffff" inkscape:current-layer="svg2" inkscape:window-maximized="1" inkscape:window-y="24" inkscape:window-height="876" inkscape:window-width="1535" inkscape:pageshadow="2" inkscape:pageopacity="0" inkscape:window-x="65">
<path id="path4180" inkscape:connector-curvature="0"


That code contains a lot of useless junk. If it is not used to display an icon, it is useless.

This is what is left of it after clean up:

svg<svg xmlns="" width="1200" height="1200" viewBox="0 0 1200 1200">
<path id="path4180" d="M983.888,575.377c187.925-18.507,293.084,231.644,148.656,358.546


Icon is not yet finalised. It still requires optimisation.

If you think the code above contains just a little bit of useless tags, so it is not a big deal, it was a short example. There are icons in some icon sets with tens of kilobytes of junk data.


Clean up process does not optimise the icon. It only does the following:

It is done with the cleanupSVG() function from Iconify Tools.

Optimisation is done later, after parsing palette.

Released under the Apache 2.0 License.