Course contentsShow
← Web Development
Lesson 2041 of 2,98237. Image and Asset OptimizationFree lesson

Accessible SVG Icons

Implement proper ARIA labels, roles, and title elements to make SVG icons accessible to screen readers.

Accessible SVG Icons

What you'll learn: How to make your SVG icons understandable to screen readers and assistive technologies, ensuring all users can interact with your interface.

Why Accessibility Matters for SVG Icons

SVG icons might look perfect to sighted users, but screen readers don't "see" them. Without proper markup, an icon could be completely invisible to assistive technologies, or worse—announced in a confusing way. Think of it like having a road sign with no text description for someone who can't see the symbol.

Three Key Techniques

1. Role Attribute

Add role="img" to tell assistive technologies this SVG is an image, not just decorative markup:

<svg role="img" viewBox="0 0 24 24">
  <!-- icon paths -->
</svg>

2. Title Element

Include a <title> element as the first child of your SVG. This acts like alt text for images:

<svg role="img" viewBox="0 0 24 24">
  <title>Close menu</title>
  <path d="M6 18L18 6M6 6l12 12"/>
</svg>

3. ARIA Label for Concise Descriptions

For simpler cases, use aria-label directly on the SVG:

<svg role="img" aria-label="Settings" viewBox="0 0 24 24">
  <path d="M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4..."/>
</svg>

Decorative Icons

If an icon is purely decorative (adjacent text already describes it), hide it from screen readers:

<button>
  <svg aria-hidden="true" viewBox="0 0 24 24">
    <!-- icon -->
  </svg>
  Save File
</button>

Key Takeaway: Use role="img" with either a <title> element or aria-label for meaningful icons, and aria-hidden="true" for decorative ones—this ensures screen reader users get the same information as sighted users.