SVG Accessibility Best Practices

This document defines accessibility practices for SVG files used on the web.

Accessibility testing tools generate false positives when rules are enforced without context. The practices below are focused on actual outcomes: perceptible meaning, operability, and compatibility with assistive technologies.


1. Accessible Name and Description

Required when the SVG conveys meaning or function

An SVG should expose an accessible name if it:

Use one of these patterns:

Preferred pattern: <title> + <desc> referenced via aria-labelledby

<svg role="img" aria-labelledby="svgTitle svgDesc">
  <title id="svgTitle">No DRM</title>
  <desc id="svgDesc">An emblem indicating content without digital rights management.</desc>
</svg>

Acceptable simpler pattern when only a single label is needed

<svg role="img" aria-label="Download icon">

Avoid:


2. Preserve IDs Used by Accessibility and References

Do not remove or rename IDs that are referenced by:

If an ID is referenced, it must remain consistent and resolvable after optimization.


3. Role and Decorative Handling

Meaningful SVGs

Use role="img" when the SVG represents a complete meaningful graphic.

Decorative SVGs

If an SVG is purely decorative and already accompanied by accessible text, hide it from assistive technology:

<svg aria-hidden="true" focusable="false">

Avoid using role="presentation" unless you are intentionally suppressing semantics and the SVG is truly decorative.


4. Keyboard and Focus Behavior

Only required when the SVG itself is interactive.

If an SVG is used as an interactive control, it must be:

If the SVG is not interactive (purely an image), do not force focus behavior into it.


5. Forced-Colors (High Contrast) Support

SVGs must remain perceivable in forced-colors mode.

Requirements:

Example:

@media (forced-colors: active) {
  .icon { stroke: CanvasText; fill: CanvasText; }
  .accent { stroke: Highlight; fill: Highlight; }
}

If the SVG is still clearly perceivable without a special forced-colors block, do not add one just to satisfy a checklist.


6. Contrast Requirements (Graphical Objects)

For non-text graphical elements that convey meaning (including focus indicators):

This is a perceptual outcome, not a “pattern check.” A tool warning is not proof of failure.


7. ViewBox and Scaling

Include viewBox whenever the SVG is intended to scale responsively.

Do not remove viewBox for optimization unless you have a verified reason and you have tested responsive rendering.


8. What Must Not Be Removed During Optimization

Do not remove the following if they contribute to meaning or behavior:


9. What Is Not Required (Avoiding False Positives)

To avoid chasing false positives, these are not blanket requirements:

Accessibility must be measured against real usage context, not static rules alone.


10. Outcome-Based Testing

Automated checks are useful, but they are not the source of truth.

Validate SVG accessibility by:


Summary