Open an .svg icon exported straight out of Adobe Illustrator or Inkscape in your code editor and you will find XML prologs, DOCTYPE declarations, RDF metadata blocks, empty nested <g> wrappers, and Bézier coordinates carried out to five decimal places like 28.49981. Inlining twenty unoptimized icons into a page bloats your initial HTML document and triggers React console warnings over hyphenated attributes.
Where SVG Byte Savings Come From
| Cleanup Pass | What Gets Stripped | Typical Savings |
|---|---|---|
| XML, DOCTYPE & RDF Metadata | <?xml...>, comments, editor namespaces | 25% – 45% on small icons |
| Coordinate Precision (2 dec) | 32.00000 → 32, 28.49981 → 28.5 | 15% – 30% on complex paths |
| Empty Groups & Whitespace | Nested <g></g> and indentation | 8% – 15% |
The `currentColor` Trick for Effortless Dark Mode Icons
- Stop shipping duplicate light/dark SVG files: Replacing hardcoded
stroke="#0F172A"withstroke="currentColor"lets your SVG inherit the exact CSScolorof its parent button or link—including hover states and dark-mode switches! - Inspecting complex path commands: Need to debug individual
M,C, orAcurve segments inside a custom illustration? Load the cleaned path into our SVG Path Visualizer. - URL-encoded CSS Data URIs vs Base64: For custom select arrows in CSS, URL-encoded UTF-8 SVGs (escaping only
#,<,>, and%) are ~25% smaller and compress better under Brotli than Base64!
Frequently Asked Questions
Why should I never delete `viewBox` when removing `width` and `height`?
viewBox defines the internal coordinate grid of your vector shapes. Without it, scaling an SVG via CSS crops the graphic instead of resizing it proportionally.
Does rounding to 1 decimal place ever distort small 16×16 icons?
Occasionally on tight circular arcs inside a 0 0 16 16 grid. Sticking to 2 decimals preserves sub-pixel smoothness while capturing almost all file-size wins.