Why is accessibility important for SVGs?
Accessibility ensures that users relying on assistive technologies, like screen readers, can understand and interact with SVG content, fostering an inclusive web experience.
Methods for making SVGs accessible on websites, ensuring they are inclusive and understandable for users relying on assistive technologies. Detailed explanations of using <img> with alt or aria-label and inline <svg> with <title> or aria-labelledby to optimize SVG accessibility.
Scalable Vector Graphics (SVGs) are widely used to deliver rich and crisp visuals on the web. However, without proper accessibility features, SVGs can exclude users who rely on assistive technologies, such as screen readers. By implementing thoughtful accessibility practices, you can make SVGs understandable and inclusive for all users.
Below, I explore four key methods for implementing accessible SVGs and explain why they work effectively.
<img> + role="img" + alt="[desc]" #Let’s look at an example for method 1:
<img role="img" alt="Level AAA conformance, W3C WAI Web Content Accessibility Guidelines 2.2" src="https://www.w3.org/WAI/WCAG22/wcag2.2AAA-blue.svg">
Explanation:
What is being done? The <img> tag, which natively serves as an image container, is given the role="img" attribute for explicit semantic clarity. The alt attribute provides a concise textual description of the SVG content.
Why it works:
alt attribute ensures the description is accessible to screen readers, allowing visually impaired users to understand the image’s purpose.role="img" clarifies the element’s role in scenarios where semantic nuances might be lost.<img>.<img> + role="img" + aria-label="[desc]" #Let’s look at an example for method 2:
<img role="img" aria-label="Level AAA conformance, W3C WAI Web Content Accessibility Guidelines 2.2" src="https://www.w3.org/WAI/WCAG22/wcag2.2AAA-blue.svg">
Explanation:
What is being done? The <img> tag is used again with role="img", but the descriptive text is provided via the aria-label attribute instead of alt.
Why it works:
aria-label is used to supply an accessible name for the element, providing the same level of detail as alt for screen readers.alt attribute might already serve a different purpose (e.g., decorative images where alt="" is used).<svg> + role="img" + <title> #Let’s look at an example for method 3:
<svg role="img" ...>
<title>Level AAA conformance, W3C WAI Web Content Accessibility Guidelines 2.2</title>
[svg design]
</svg>
Explanation:
What is being done? The <svg> tag is directly used to embed the vector graphic, with role="img" defining it as an image. A <title> element is nested within the SVG to provide a descriptive text.
Why it works:
<title> as the accessible name of the graphic, ensuring users understand its meaning.role="img" reinforces the purpose of the SVG, making its semantics explicit.<title> is part of the SVG’s content structure.<svg> + role="img" + <title> + aria-labelledby="[ID]" #Let’s look at an example for method 4:
<svg role="img" aria-labelledby="conformance" ...>
<title id="conformance">Level AAA conformance, W3C WAI Web Content Accessibility Guidelines 2.2</title>
[svg design]
</svg>
Explanation:
What is being done? The <svg> tag includes a role="img" attribute and references the <title> element using the aria-labelledby attribute. The <title> has a unique id that links it to the aria-labelledby attribute.
Why it works:
aria-labelledby provides an explicit reference to the element that serves as the accessible name, ensuring screen readers prioritize the linked description.<desc> for detailed explanations) are used within the SVG.Each method offers distinct advantages depending on the SVG’s context and complexity. For example, simpler static graphics work well with Methods 1 or 2 using the <img> element, as these methods focus on straightforward descriptions. In contrast, Methods 3 and 4 are ideal for inline SVGs, with Method 4 particularly excelling when additional details or multiple descriptive elements like <desc> are required to enhance clarity. For example:
<img> tags.By employing these techniques, web developers can ensure their visual content is accessible to all users, fostering an inclusive and equitable digital experience. Whether using <img> with alt or aria-label, or embedding inline <svg> with <title> or aria-labelledby, these methods ensure that SVGs are meaningful and usable for everyone.
Also read about user-friendly images in websites.
Most common questions and brief, easy-to-understand answers on the topic:
Accessibility ensures that users relying on assistive technologies, like screen readers, can understand and interact with SVG content, fostering an inclusive web experience.
alt attribute with <img> tags for SVGs?The alt attribute provides a concise description of the SVG content, making it accessible to screen readers and improving the overall user experience.
aria-labelledby instead of aria-label for SVGs?Use aria-labelledby for more complex SVGs where a descriptive element like <title> or <desc> is needed to provide detailed context, as it allows linking to these elements for better clarity.
<title> element alone make an inline SVG accessible?Yes, the <title> element provides an accessible name for the SVG, which screen readers interpret, but pairing it with role="img" enhances semantic clarity.
<img> or <svg>?Use <img> for simpler, static SVGs requiring basic descriptions and <svg> for more complex or interactive graphics needing inline descriptions and advanced accessibility features.
Sources and recommended, further resources on the topic:
License: Accessible SVGs by Jonas Jared Jacek is licensed under CC BY-SA 4.0.
This license requires that reusers give credit to the creator. It allows reusers to distribute, remix, adapt, and build upon the material in any medium or format, for noncommercial purposes only. To give credit, provide a link back to the original source, the author, and the license e.g. like this:
<p xmlns:cc="http://creativecommons.org/ns#" xmlns:dct="http://purl.org/dc/terms/"><a property="dct:title" rel="cc:attributionURL" href="https://www.uxgem.com/articles/svg-accessibility">Accessible SVGs</a> by <a rel="cc:attributionURL dct:creator" property="cc:attributionName" href="https://www.j15k.com/">Jonas Jared Jacek</a> is licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank" rel="license noopener noreferrer">CC BY-SA 4.0</a>.</p>For more information see the UXgem legal page.
“Want your users to fall in love with your designs? Fall in love with your users.”