Skip to content

SVG optimizer

Shrink bloated SVG exports into clean, lightweight markup while comparing before and after live.

Drop SVG files here

Single SVG for live code inspection, or multiple SVGs for batch minification

Or paste <svg> markup below:

How to use SVG optimizer

  1. Add SVG files or paste raw markup. Drop one or multiple vector files onto Drop SVG files here, click Choose SVG files, paste XML into the editor, or select Load sample SVG.
  2. Tune coordinate precision and cleanup rules. Set Coordinate decimals between 1 and 4, and toggle metadata removal, ID pruning, Responsive viewBox, or Convert fills/strokes to currentColor.
  3. Compare live visual rendering across backdrops. Switch the preview bar between Grid, Light, and Dark surfaces to verify curves, transparency, and dark stroke visibility alongside live byte savings.
  4. Copy markup or batch-download a ZIP archive. Click Copy SVG for inline components, select Save optimized SVG for a -min.svg file, or download multiple icons together as optimized-svgs.zip.

Everything runs in this browser tab. Nothing you paste or open is uploaded or logged, so it's safe for keys, tokens and private data.

Stripping editor metadata, empty groups, and unused SVG attributes

Vector graphics exported from desktop and browser design tools routinely carry 30% to 60% non-rendering XML overhead. Stripping non-visual namespaces, redundant wrapper elements, and default presentation attributes shrinks inline component bundles and standalone .svg icons while keeping every Bézier curve, stroke cap, and coordinate visually identical inside your tab.

Cleaning Figma, Illustrator, and Inkscape export namespaces

Design editors embed private round-trip state so projects reopen with layer names and artboard guides intact. Leaving Strip XML header & comments and Strip editor metadata (Figma, Inkscape, Illustrator) checked removes <?xml ...?> preambles, <!DOCTYPE> declarations, HTML comments, RDF <metadata> blocks, <sodipodi:namedview> tags, and inkscape:*, sodipodi:*, sketch:*, and serif:* attributes.

That same pass clears data-name layer labels, xml:space="preserve", legacy version="1.1" flags, deprecated enable-background directives, and unused xmlns:xlink declarations when no xlink:* attribute remains. If you want to audit raw node nesting before minification, open the file in the XML formatter to inspect deeply indented vendor blocks first.

Collapsing wrapper groups and sanitizing untrusted SVG scripts

Illustration exports frequently wrap single paths inside three or four nested <g> containers left behind after ungrouping artboards. Under the W3C SVG 2 Document Structure Specification, <g> elements without presentation attributes, transforms, or IDs contribute zero visual styling, so Collapse empty groups (<g>) iteratively unwraps attribute-free wrappers and deletes empty <g/> and <defs/> nodes.

Because third-party vector downloads can hide active payloads, every run also strips <script> blocks, inline on* event handlers, javascript: URIs, and external CSS @import or remote url() beacons. Spaces inside <text> elements are isolated before inter-tag whitespace collapses, ensuring typographic labels never lose deliberate word spacing.

Why do aggressive SVG minifiers break gradients, masks, or path curves?

Aggressive SVG minifiers corrupt artwork when naive regular expressions round path coordinates blindly or strip id attributes that internal paint servers still reference. Preserving visual fidelity requires parsing SVG path commands by parameter count and scanning every CSS, ARIA, and URL reference before deleting a single element identifier.

Command-aware path decimal rounding across 1 to 4 places

Desktop editors often serialize cubic curves with 4 to 8 decimal places such as M 38.5000,61.2500. Adjusting Coordinate decimals between 1 and 4 (default 2) rounds path coordinates, points, viewBox, transform matrices, and geometric attributes (x, y, cx, cy, r, rx, ry, width, height, stroke-width) while stripping trailing zeros like .000.

Naive regex rounders often fuse adjacent decimals or corrupt compact elliptical arc flags permitted by the W3C SVG 2 Path Data Grammar Specification, where 7-parameter A commands pack single-bit 0 and 1 flags without spaces (a4 4 0 014-4). Our parser steps through M, L, H, V, C, S, Q, T, A, and Z arity token by token so arc flags and negative offsets stay valid.

Reference-safe ID pruning for gradients, masks, and sprite sheets

Blindly deleting id attributes breaks <linearGradient>, <radialGradient>, <clipPath>, <mask>, and <filter> definitions that shapes reference via fill="url(#id)". When Remove unreferenced IDs is active, the optimizer first indexes every #id target inside url(), href, xlink:href, aria-labelledby, aria-describedby, and embedded <style> selectors, removing only orphaned layer names like id="Layer_1".

External icon sprite workflows also rely on <use href="sprite.svg#icon-name"> references from outside the file itself, so the cleaner preserves every id placed on <symbol> and <view> elements automatically. Architecture diagrams behave the same way when you turn Mermaid diagram syntax into standalone SVG files and minify the exported flowchart markup for documentation sites.

Responsive viewBox scaling vs fixed width and height attributes

Hardcoded width="120px" and height="120px" attributes lock an SVG to a fixed pixel box and prevent fluid CSS sizing inside modern grid or button layouts. Under the W3C SVG 2 Coordinate Systems and viewBox Specification, the four-number viewBox (min-x min-y width height) establishes an internal user coordinate grid so parent CSS selectors control rendered dimensions cleanly.

Enabling Responsive viewBox (drop fixed width/height) checks whether a valid viewBox already exists; if an older export only specifies physical or pixel dimensions (px, pt, pc, in, cm, mm at 96 px per inch), it synthesizes viewBox first before removing root width and height. When downstream slides or email clients reject vector markup, you can rasterize vector SVG graphics into PNG, JPG, or WebP after cleanup.

Control in Optimization options Default Transformation applied When to adjust
Coordinate decimals (1–4) 2 Rounds path d, points, transform, viewBox, and shape coordinates Set 3 or 4 on tiny 12 px grids or dense maps
Strip XML header & comments Checked Removes UTF-8 BOM, <?xml ...?>, <!DOCTYPE>, and comments Uncheck for legacy parsers needing XML preambles
Strip editor metadata Checked Deletes <metadata>, <sodipodi:namedview>, editor namespaces, and data-name Uncheck to retain embedded RDF license blocks
Remove unreferenced IDs Checked Strips unused ids while keeping url(#id), ARIA, <style>, and <symbol> IDs Uncheck if scripts query specific <path id> nodes
Shorten hex colors & defaults Checked Converts rgb() to hex, shortens #rrggbb to #rgb, drops opacity="1" Keep enabled on web and app vector assets
Collapse empty groups (<g>) Checked Deletes empty <g/> and <defs/> tags and unwraps bare <g> wrappers Uncheck if CSS targets svg > g > path selectors
Responsive viewBox Unchecked Synthesizes viewBox if missing, then drops root width and height Enable for fluid CSS components; skip for fixed <img> tags
Pretty-print indented markup Unchecked Formats 2-space indented XML instead of single-line output Enable when reviewing diffs in Git pull requests

Theming icons with currentColor and batch-saving optimized ZIPs

Design tools export monochrome icons with fixed hex codes such as stroke="#111111" or fill="#000000", blocking CSS hover states and dark-mode text inheritance in React, Svelte, Vue, or Astro components. Rewriting paint attributes alongside shortening hex colors turns static exports into theme-adaptive icons ready for single-file copy or batch archive download.

Converting hardcoded fills and strokes without filling hollow paths

Checking Shorten hex colors & defaults converts verbose rgb(255, 255, 255) declarations into lowercase hex, condenses matching six-digit pairs into three-digit #fff shorthand, and removes redundant opacity="1", fill-opacity="1", and stroke-opacity="1" attributes. Checking Convert fills/strokes to currentColor goes one step further using the keyword defined in the MDN CSS Color Value and currentColor Reference so icons inherit their parent button or link color property automatically.

To prevent turning stroked outline icons into solid silhouettes, the converter skips fill="none", transparent, and url(#...) gradient or pattern references. If you are building a multi-tone illustration rather than a monochrome icon and need exact palette values from a screenshot, sample hex codes first in the browser-based image color picker.

Previewing backdrops and packaging multi-icon ZIP archives locally

Side-by-side Original and Optimized cards render sanitized Blob URL previews up to 360 px wide with a live byte-delta badge (before → after and percentage saved). Toggling currentColor automatically switches the preview bar from the 16 px Grid checkerboard to Light (#ffffff), and you can test contrast against Dark (#18181a) before clicking Copy SVG or Save optimized SVG (<name>-min.svg).

Dropping two or more .svg files queues the entire set in local tab memory without uploading proprietary logos or unreleased UI kits. Clicking Save optimized SVGs (.zip) runs your chosen settings across every file, deduplicates filenames with -min.svg suffixes, and bundles optimized-svgs.zip inside a dedicated Web Worker.

Tip: Enable Pretty-print indented markup when reviewing cleaned SVG changes in a pull request, then uncheck it before copying single-line production markup into an icon component library.

Questions

Will removing unreferenced IDs break SVG gradients, clipPaths, or sprite symbols?

No. Before stripping any identifier, the optimizer scans url(#id) paint references, href and xlink:href links, aria-labelledby and aria-describedby attributes, and #id selectors inside <style> blocks. It also leaves all <symbol> and <view> element IDs untouched so external sprite sheets continue working.

What coordinate decimal precision should I choose for UI icons versus detailed illustrations?

Two decimal places is the safest default for standard 16 px to 64 px interface icons, trimming verbose floating-point coordinates from design editors without visible curve shifts. Increase Coordinate decimals to 3 or 4 when optimizing intricate technical diagrams, maps, or icons built inside tiny 12-unit viewBoxes.

How does converting fills and strokes to currentColor handle hollow outline icons?

Enabling Convert fills/strokes to currentColor rewrites explicit hex and RGB paint values while deliberately skipping none, transparent, and url(#gradient) references. Hollow outline icons keep fill="none" intact instead of turning into solid shapes, and the preview automatically switches from Grid to Light so dark strokes stay visible.

What happens if an SVG lacks a viewBox when I drop fixed width and height?

When you enable Responsive viewBox (drop fixed width/height) on a file that only declares root width and height attributes, the optimizer first synthesizes a matching viewBox="0 0 width height" attribute using CSS 96 px/in unit rules. Only after locking in that coordinate space does it remove fixed dimensions.

Does the optimizer sanitize embedded scripts or tracking URLs inside untrusted SVGs?

Yes. Because SVG is an XML document format capable of carrying executable code, every optimization pass strips <script> elements, inline on* event attributes, javascript: links, CSS @import rules, and external url() network beacons. Preview rendering additionally removes foreignObject and SMIL animation tags before mounting local Blob URLs.

How do I minify an entire folder of SVG icons at once?

Select or drag multiple .svg files onto Drop SVG files here in one step. The first icon opens in the live inspector so you can test your settings, and clicking Save optimized SVGs (.zip) processes the entire queue locally into optimized-svgs.zip with -min.svg filenames.

Updated