SVG Optimizer
Clean up SVG markup by removing comments, editor metadata (Inkscape/Sodipodi namespaces), the XML declaration and redundant whitespace. Conservative by design — it never touches path data, so the shape never changes.
Paste SVG markup and toggle which cleanups to apply. Each option is independent, so you can see the size drop and preview update as you enable or disable a step. The result is downloadable as clean, smaller markup.
Options
SVG source — 365 B
Optimized — 142 B(61% smaller)
Learn more
What SVG optimization does
SVG optimization is the process of reducing an SVG file's size without changing its visual output. Because SVG is XML-based text, it accumulates bloat that raster formats don't carry: editor metadata (Inkscape layer names, Illustrator generator tags), comments explaining the file's history, redundant attributes with default values, and whitespace added for human readability. An optimizer strips these dead-weight elements, shrinking the file while producing pixel-identical rendering.
The motivation is performance. SVGs are typically used for icons, logos, and illustrations on websites where every kilobyte counts. A 5 KB icon that appears on every page of a high-traffic site costs 5 KB × page views in bandwidth — and because SVG is text, it also costs CPU time to parse and render. Optimization reduces both: smaller files transfer faster, and simpler XML parses faster. For icon systems that bundle hundreds of SVGs into a sprite or font, optimization is the difference between a 200 KB sprite and a 600 KB one.
SVG structure and elements
An SVG document is an XML tree with a root <svg> element containing shape elements — <path>, <rect>, <circle>, <line>, <polygon>, <polyline>, <ellipse> — and grouping elements like <g>. The <path> element is the most powerful and most common: its d attribute contains a sequence of drawing commands (M for move, L for line, C for cubic bezier, Z for close path) that can describe virtually any shape. Understanding this structure is essential for optimization, because most size reduction comes from simplifying path data and removing unnecessary elements.
SVG also carries metadata that has no visual effect: the XML declaration (<?xml version="1.0"?>), DOCTYPE declarations, comments, and custom namespace attributes added by editors. Inkscape embeds sodipodi: and inkscape: namespace attributes tracking layers, guides, and tool state. Illustrator adds a <metadata> block with the generator's version history. None of these affect rendering — browsers ignore unknown namespaces — but they add bytes to every file the editor exports.
Common optimization techniques
The simplest optimizations are structural removals: delete comments, metadata blocks, the XML declaration, and editor-specific attributes. These are provably safe — they contain no rendering information — and often recover 10–30% of an editor-exported file's size. Removing redundant attributes is similar: fill="#000000" can become fill="#000" (shorter hex), and attributes with values matching their defaults (fill-opacity="1", stroke-width="1") can be dropped entirely.
Path optimization is where the real gains live. Path data can be minified by removing unnecessary spaces (M 10 20 → M10 20), using relative commands where they're shorter than absolute ones, rounding coordinates to fewer decimal places, and converting between command types (a line with equal start and end points is pointless). More aggressive optimizers simplify curves by removing redundant control points or merging consecutive line segments. Tools like SVGO apply these transformations with configurable aggressiveness — conservative profiles only make provably safe changes, while aggressive profiles trade tiny visual differences for maximum size reduction.
SVG vs. PNG vs. WebP
Choosing between SVG and raster formats is a tradeoff between scalability and complexity. SVG is resolution-independent — it renders crisply at any size, from a 16px favicon to a billboard — and its file size is proportional to the complexity of the artwork, not its dimensions. PNG is resolution-dependent: a crisp icon needs a 1x, 2x, and 3x asset for different screen densities, and its size grows with pixel count. WebP improves on PNG's compression but still has the same resolution-dependence.
SVG wins for simple, geometric artwork: icons, logos, charts, and illustrations with flat colors and clean edges. Raster formats win for complex, photographic content: images with gradients, textures, noise, or thousands of colors, where an SVG would require an enormous path description or embedded bitmap. A good rule of thumb: if the artwork could be described as a list of shapes and paths, use SVG; if it looks like a photograph, use WebP or AVIF.
Performance implications and optimization tooling
The performance impact of SVG optimization extends beyond file size. A simpler XML tree parses faster, which matters for SVGs injected inline into HTML (where the browser must parse the SVG as part of the document) or for icon systems that load hundreds of symbols. Complex paths with many points require more computation during rendering, especially for animations. Optimizing path data reduces both the parse time and the render time.
SVGO (SVG Optimizer) is the standard command-line tool, with plugins for each optimization pass — removing metadata, collapsing nested groups, merging paths, and more. Build pipelines integrate SVGO via webpack loaders, gulp plugins, or standalone CLI invocation. Online optimizers provide the same transformations for one-off files. The key discipline is to optimize as part of the build process, not as a manual step: an SVG that's optimized once and committed is guaranteed to stay optimized, whereas a manual step is forgotten the next time someone exports from Illustrator.
Frequently asked questions
Does this rewrite or simplify path data like SVGO does?
No — this is a conservative, text-level cleaner. It only removes things that are provably safe to drop (comments, metadata, whitespace); it never touches 'd' path data or restructures shapes, so visual output never changes.
Why does my SVG have inkscape: or sodipodi: attributes?
Vector editors like Inkscape embed their own metadata (layers, guides, tool state) directly in the SVG file. Browsers ignore it, but it adds dead weight — this tool strips it safely.
Is the live preview safe for SVG I didn't create myself?
Yes — the preview renders through an <img> tag rather than inserting the markup into the page, and browsers never execute scripts inside an SVG loaded that way.