SVG Optimizer
Shrink and sanitise SVG files: strip editor junk and scripts, round numbers, minify paths.
Try an example: Inkscape export with a script · Responsive icon (width/height removed)
How it works
Optimises an SVG file in your choice of steps and shows how many bytes each one saved: removes comments, metadata and Inkscape/Illustrator editor data, hidden and empty elements, rounds numbers, rewrites path data in its shortest form and collapses whitespace. It also removes scripts, event handlers and external references, so the result is safe to embed.
- The SVG is parsed by a strict built-in XML parser (no external entities; internal DOCTYPE entities are expanded once with a size cap, which blocks "billion laughs" files). The document is re-serialised after every step, and the byte count before/after each step is reported.
- Security (always on): removes <script>, <foreignObject>, <iframe>/<embed>/<object>, all on* event handlers, javascript: links, xml:base, CSS @import and url() references to other files, external href on <use>/<image>/<feImage> (raster data: URIs are kept), and animations that change href or event attributes. Links in <a> may point to http(s) or mailto only.
- Clean-up: comments, XML declaration, DOCTYPE and processing instructions; <metadata>, RDF and editor namespaces (Inkscape, Sodipodi, Illustrator, Sketch, Serif, Figma); elements with display:none that nothing references; unreferenced children of <defs>; empty groups, and groups without attributes are unwrapped; unused namespace declarations, version and baseProfile.
- Numbers in geometry attributes are rounded to the chosen decimal places (transforms to two more) with leading zeros dropped. Path data is re-written per segment in whichever of absolute or relative form is shorter, lines become H/V where possible, repeated command letters are omitted, and relative values are computed from the rounded current point so errors do not accumulate.
- Whitespace between elements is removed except inside text elements and xml:space="preserve". Removing width/height keeps (or creates) the viewBox so the graphic still scales.
- The optimised SVG is offered as a download (served as an attachment, never rendered on this site).
Check the optimised file visually: very low precision can shift shapes, and removing width/height changes how some programs size the image.
For scripts and AI agents
- JSON API:
POST https://svgoptimizer.usefulweb.site/api/v1/calculate(same calculation as this page) - Interface description: OpenAPI 3.1 · AI guide: llms.txt
- MCP server (Streamable HTTP):
https://svgoptimizer.usefulweb.site/mcp· tool namesvg_optimizer
Example request
curl -s -X POST https://svgoptimizer.usefulweb.site/api/v1/calculate \
-H 'content-type: application/json' \
-d '{…see OpenAPI examples…}'Related tools
- Image Compressor – Shrink JPG, PNG, WebP, AVIF or GIF images: convert, resize, strip metadata and compare sizes.