Fast and aggressive SVG minification CLI tool built in Rust, tailored specifically for shrinking SVGs for inline HTML use (like Blade templates) and standalone files.
- Extreme Minification (automatic): Removes
title,desc,metadata, comments, unusedids, hidden elements (display="none",opacity="0"), empty groups, and the<?xml...?>declaration, collapsing all whitespace and linebreaks into a single-line string. - Color Shrink (automatic): Identifies 6-digit hex color codes with identical byte pairs (e.g.,
#FF0000,#aabbcc) across all styling attributes (fill,stroke, etc.) and losslessly converts them into their 3-digit shorthands (e.g.,#f00,#abc). Leaves non-matching hex codes safely untouched. - Inline Optimization (
-i/--inline): Strips thexmlnsattributes which are unnecessary overhead for browsers when embedding SVGs directly into HTML5 code. - Decimal Precision (
-dp/--decimal-precision): Aggressively rounds all path coordinates and attributes (likeviewBox,x,y,transform) down to a user-specified number of decimal places (0-4), stripping trailing zeros.
svg-strip [OPTIONS] <input.svg> [output.svg]If no output.svg is specified, the tool will automatically save the minified file in the same directory as [ORIGINAL_NAME]_stripped.svg.
| Flag | Name | Description |
|---|---|---|
-i, --inline |
Inline Mode | Strips xmlns attributes for optimal inline HTML usage. |
-o, --output |
Stdout Mode | Prints the minified SVG directly to the terminal (stdout) instead of writing to a file. |
-dp, --decimal-precision <0-4> |
Decimal Precision | Rounds all floating point numbers inside paths and attributes to the specified number of decimal places to save bytes. |
Minify an icon for use in a web template, stripping all namespace overhead and rounding coordinates to 2 decimal places:
svg-strip -i -dp 2 raw_icon.svgOutput:
Stripped SVG written to raw_icon_stripped.svg
• Inline SVG with zero overhead
• Decimal Precision for paths rounded down to 2 decimals
• Color Shrink to convert 6-digit hex codes to 3-digit shorthands
You must have Rust and Cargo installed. Clone the repository and build the project:
git clone git@github.com:madLinux7/svg-strip.git
cd svg-strip
cargo build --releaseThe compiled binary will be available in target/release/svg-strip.
