Skip to content
Documentation

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 these elements by default.

An opt-in removeDesc pass exists for cases where accessibility is handled at the HTML level, but it is deliberately excluded from the default preset.

Animation preservation

Fully preserved

All 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 removal

IDs are only removed if they are truly unused. The cleanupIds pass builds a complete reference map before making any changes, scanning:

  • href="#id" attributes
  • url(#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 touched

HTML 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-aware

Some 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.
  • Groups with clip-path, mask, or filter are never collapsed. These attributes have different semantics when applied to a group vs an individual element.

Conservative defaults

Safe over small

SVGM deliberately defers some aggressive optimizations that other tools apply by default:

  • Elements with visibility="hidden" or opacity="0" are not removed. They may be animated into visibility or referenced by JavaScript.
  • Groups are only collapsed when it is provably safe: no attribute conflicts, no special group-level attributes.
  • 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.

Comparison with SVGO

BehaviorSVGM safeSVGO
<desc> and <title> preservedDefaultRemoved by default
Animation elements preservedAlwaysMay remove targets
IDs removed only if unusedYesAggressive removal
<symbol>/<defs> with id keptAlwaysMay remove
<foreignObject> untouchedAlwaysMay parse/optimize
fill="black" on <svg> preservedYesMay remove
visibility="hidden" elements keptYesRemoved
Groups with clip-path/mask/filterNever collapsedMay over-collapse