Color scheme

SVG Accessibility

Every SVG on your page falls into one of two categories from a screen reader's perspective: decorative or informative. Decorative SVGs exist to support content that is already described elsewhere. Informative SVGs carry meaning that would be lost without them. Getting this distinction right is the foundation of accessible icon work. The mechanics that follow from it: which attributes to add, which to omit, how to handle buttons and links. All of these depend on answering that one question first.

Decorative SVGs

A decorative SVG adds visual interest or reinforces meaning that is already communicated in nearby text. A checkmark icon next to the word "Complete", a home icon inside a nav link that already says "Home", a decorative divider between sections. These all fall into this category. Screen readers should skip them entirely.

Two attributes work together to hide an SVG from assistive technology:


    <svg aria-hidden="true" focusable="false">
        <use href="#icon-check"></use>
    </svg>
  • aria-hidden="true" removes the element and all its children from the accessibility tree. Screen readers will not announce it.
  • focusable="false" is needed for Internet Explorer and older Edge, which made SVGs focusable by default. Modern browsers do not require it, but it is harmless and worth including for robustness.
Never Put aria-hidden on a Focusable Element

aria-hidden="true" hides the element from the accessibility tree but does not remove it from tab order. If the SVG itself or a child element is focusable, keyboard users can still tab to it while screen reader users hear nothing. Always ensure aria-hidden elements are not focusable.

role="img" and title

When an SVG conveys meaning that is not communicated anywhere else on the page, it must be labeled. A standalone icon that represents an action, a logo, a chart, or a status indicator all fall into this category.

The pattern for a labeled SVG uses three parts: role="img" to identify it as an image to assistive technology, a <title> element as the first child of the SVG with the accessible name, and aria-labelledby connecting the outer SVG to that title by ID:


    <svg role="img" aria-labelledby="icon-title-star">
        <title id="icon-title-star">Favorite</title>
        <use href="#icon-star"></use>
    </svg>

Without role="img", some screen readers treat the SVG as a group and announce its contents differently across browsers. Without aria-labelledby, some screen readers ignore the <title> entirely. Using all three together produces consistent behavior across NVDA, JAWS, and VoiceOver.

title vs. desc

<title> provides the accessible name: the short label that identifies what the SVG is. <desc> provides a longer description for complex graphics like charts or diagrams where the title alone is not sufficient. For icons, <title> alone is almost always enough. Add <desc> only when the SVG communicates data or spatial relationships that require more than a few words to convey.


    <!-- Icon: title only -->
    <svg role="img" aria-labelledby="chart-title chart-desc">
        <title id="chart-title">Monthly Revenue</title>
        <desc id="chart-desc">
            Bar chart showing revenue from January through June.
            June was the highest month at $42,000.
        </desc>
        <!-- chart paths -->
    </svg>

The Decision Tree

Before adding any accessibility attributes to an SVG, work through these questions in order:

  • Is the SVG purely decorative? If yes: add aria-hidden="true" and focusable="false". Stop here.
  • Is the SVG inside a button or link that already has a visible text label? If yes: the button or link label covers the icon. Add aria-hidden="true" to the SVG. Stop here.
  • Is the SVG inside an icon-only button or link with no visible text? If yes: label the button or link with aria-label or aria-labelledby. Add aria-hidden="true" to the SVG itself since the interactive element carries the label. Stop here.
  • Is the SVG a standalone informative image? If yes: add role="img", a <title> as the first child, and aria-labelledby pointing to the title ID.

Pairing SVGs with Links and Buttons

Icons inside interactive elements need careful handling. The goal is always that the interactive element announces exactly one clear label: not the icon's title, not a redundant combination of icon and text, and not silence.

Icon with Visible Text Label

When a button or link has visible text alongside the icon, the text provides the accessible name. Hide the icon:


    <button type="button">
        <svg aria-hidden="true" focusable="false">
            <use href="#icon-arrow-right"></use>
        </svg>
        Continue
    </button>
    <!-- Announced: "Continue, button" -->

Icon-Only Button

When there is no visible text, the interactive element itself needs a label. Use aria-label on the button or link, and hide the SVG:


    <button type="button" aria-label="Close dialog">
        <svg aria-hidden="true" focusable="false">
            <use href="#icon-close"></use>
        </svg>
    </button>
    <!-- Announced: "Close dialog, button" -->

An alternative to aria-label is visually hidden text inside the button. This approach is more robust for translation tools and some AT configurations:


    <button type="button">
        <svg aria-hidden="true" focusable="false">
            <use href="#icon-close"></use>
        </svg>
        <span class="visually-hidden">Close dialog</span>
    </button>

The visually-hidden class is already defined in this course site's utilities stylesheet. You do not need to rewrite it for each project. See CSS Architecture for how utility classes fit into the layer stack.

aria-label vs. Visually Hidden Text

Both approaches work. aria-label is quicker to write. Visually hidden text is picked up by browser translation features like Chrome's built-in translator, which ignores aria-label values. For a student project either is acceptable; in production, visually hidden text is generally preferred.

Icon-Only Link

The same pattern applies to links. A social media icon link with no visible text needs a label on the <a> element:


    <a href="https://github.com/username" aria-label="GitHub profile">
        <svg aria-hidden="true" focusable="false">
            <use href="#icon-github"></use>
        </svg>
    </a>
    <!-- Announced: "GitHub profile, link" -->

Accessibility in Action

The demo below uses the same inline sprite and <use> pattern from SVG Sprites. Pick a scenario to see a live example, what pattern it follows, and what a screen reader should announce. The announcement text is guidance only; run a real screen reader test using the checklist later on this page.

Your order is confirmed.
Warning

Decorative Beside Text

The nearby text already conveys the meaning. Hide the SVG with aria-hidden="true" and focusable="false" so assistive technology skips it.

Expected Announcement

Guidance only. Your screen reader may phrase this differently.

Your order is confirmed.

use and the Shadow DOM

The <use> element renders a clone of its referenced symbol inside a shadow DOM. This creates a subtle accessibility problem: a <title> element placed inside a <symbol> definition is not reliably exposed through the shadow DOM to assistive technology. Screen readers in some browser and AT combinations will not announce it.

The practical implication is that you should not rely on titles inside <symbol> definitions for accessibility. Instead, place the accessible label on the <svg> wrapper that contains <use>, either with aria-label directly or with a <title> in the wrapper SVG itself:


    <!-- Unreliable: title inside symbol -->
    <symbol id="icon-star" viewBox="0 0 24 24">
        <title>Star</title> <!-- May not be exposed through use -->
        <path d="..."></path>
    </symbol>

    <!-- Reliable: label on the wrapper SVG -->
    <svg role="img" aria-label="Favorite">
        <use href="#icon-star"></use>
    </svg>

Screen Reader Quick Test

You do not need a full assistive technology setup to do a basic screen reader test. Every major operating system ships with one built in:

  • macOS and iOS: VoiceOver. Enable with Command + F5 on Mac, or triple-click the side button on iPhone. Navigate with Tab and arrow keys on Mac; swipe on iOS.
  • Windows: Narrator is built in (Windows key + Ctrl + Enter). NVDA is free to download and more representative of real-world screen reader usage.
  • Android: TalkBack. Enable in Accessibility settings.

For icons specifically, listen for these things during your test:

  • Decorative icons: should be completely silent. If VoiceOver or NVDA announces anything when you navigate past the icon, aria-hidden="true" is missing or applied incorrectly.
  • Icon-only buttons: should announce the button label you provided, followed by "button." If you hear "button" with no label, the aria-label or visually hidden text is missing.
  • Icon-only links: should announce the link label followed by "link." Same as above if you hear only "link."
  • Informative standalone SVGs: should announce the <title> text followed by "image." If you hear nothing, check role="img" and aria-labelledby.
Test in at Least Two Browsers

Screen reader and browser combinations behave differently. VoiceOver with Safari is the primary combination on Mac and iOS. NVDA with Firefox or Chrome covers most Windows users. A test that passes in one combination can fail in another, so checking two is a meaningful minimum.

Check Your Understanding

Put your new skills to the test with this coding challenge. Review the broken icon markup below, fix every accessibility problem you can find, and use the copy icon to copy your completed code and paste it as a prompt to your AI assistant for feedback.


        <!--
            The markup below has multiple accessibility problems.
            Fix every issue you find.

            Hint: there are at least four distinct problems.
        -->

        <!-- 1. Decorative icon next to a text label -->
        <p>
            <svg>
                <use href="#icon-check"></use>
            </svg>
            Your order is confirmed.
        </p>

        <!-- 2. Icon-only close button -->
        <button type="button">
            <svg role="img" aria-label="Close">
                <use href="#icon-close"></use>
            </svg>
        </button>

        <!-- 3. Standalone informative icon -->
        <svg>
            <use href="#icon-warning"></use>
        </svg>

        <!-- 4. Icon-only nav link -->
        <a href="/home">
            <svg aria-label="Home">
                <use href="#icon-home"></use>
            </svg>
        </a>

    

Resources