Safety
SVGM is conservative by default. Every optimization must be provably safe. If there is any doubt about whether a removal changes rendering, accessibility, or behavior, SVGM leaves it alone.
Accessibility-sensitive removals
Preserved by default<desc> and <title> elements carry accessibility semantics. Screen readers use them to describe SVG content to users. SVGM never removes a custom description or a title.
The removeDesc pass, enabled in the default preset and off in safe, only strips empty <desc>elements and editor boilerplate such as "Created with...".
Animation preservation
Fully preservedAll SVG animation elements are fully preserved: <animate>, <animateTransform>, <animateMotion>, and <set>.
SVGM tracks animation targets before any removal pass runs. It resolves href / xlink:href on animation elements (defaulting to the parent element when no explicit target is set). Elements in the animation target set are never removed, even if they appear invisible. They may become visible during animation.
Reference safety
Verified before removalIDs are only removed if they are truly unused. The cleanupIds pass builds a complete reference map before making any changes, scanning:
href="#id"attributesurl(#id)references in presentation attributes- SMIL timing attributes (e.g.
begin="id.click") - CSS selectors inside
<style>elements
<symbol> and <defs> elements with an id attribute are never removed. They may be referenced by external documents or JavaScript that SVGM cannot analyze.
foreignObject behavior
Never touchedHTML and XHTML content inside <foreignObject> elements is left completely alone. SVGM does not parse, optimize, or modify foreignObject children in any way. This prevents accidental corruption of embedded HTML content.
Inheritance-sensitive behavior
Context-awareSome attributes that appear redundant actually affect rendering through CSS inheritance. SVGM understands these cases:
fill="black"on<svg>is preserved. It is inherited by all child elements, and removing it changes the cascade.- Default attributes are only removed when they are safe to inherit. The ancestor chain, including
style=""declarations, is checked first. - Groups with
clip-path,mask, orfilterare never collapsed. These attributes have different semantics when applied to a group vs an individual element.
Conservative defaults
Safe over smallSVGM deliberately defers some aggressive optimizations that other tools apply by default:
- Elements with
visibility="hidden"oropacity="0"are not removed. They may be animated into visibility or referenced by JavaScript. - Leaf shapes with
fill="none"andstroke="none"are kept. They can still act as hit areas or clip paths. - Groups are only collapsed when it is provably safe: no attribute conflicts, no special group-level attributes. Direct children of
<switch>are never collapsed or removed. - While a
<style>or<script>element remains, SVGM leaves the document structure alone so selectors and scripts keep matching. - Every removal is gated by a safety check. If an element has an
id, sits inside<defs>/<symbol>, is an animation target, or carries effect attributes, it is preserved.
For maximum caution, use --preset safe to limit optimization to removal, normalization, and output passes only, skipping all structural and geometric transforms.
Parity with SVGO
Since 0.4.0Every optimization SVGO 4 refuses as unsafe is refused by SVGM too, after an audit of all 34 default passes against SVGO's source and fixtures. A 414-file pixel comparison shows no rendering difference between SVGM's output and SVGO's, and a 433-input robustness corpus produces no hangs, panics, empty outputs, or non-idempotent files.
Comparison with SVGO
| Behavior | SVGM safe | SVGO |
|---|---|---|
| Animation elements preserved | Always | May remove targets |
| IDs removed only if unused | Yes | Aggressive removal |
| <symbol>/<defs> with id kept | Always | May remove |
| <foreignObject> untouched | Always | May parse/optimize |
| fill="black" on <svg> preserved | Yes | May remove |
| visibility="hidden" elements kept | Yes | Removed |
| Groups with clip-path/mask/filter | Never collapsed | May over-collapse |