-
-
Notifications
You must be signed in to change notification settings - Fork 778
How to make SVGs and other images WCAG compliant
Jessica Cheng edited this page Mar 27, 2023
·
22 revisions
Using the alt
property in img
HTML tags or Accessible Rich Internet Applications (ARIA) labels with Scalable Vector Graphics (SVGs) and other images is important so that all images on the Hack for LA website are Web Content Accessibility Guidelines (WCAG) compliant. This pages explains how the Website Team deals with SVGs and other images to make them WCAG compliant.
Use an img
HTML tag with the SVG or image as for the src
and an alt
attribute (Website Team's preferred method)
Example of an image in an img
tag that needs an alt
attribute:
<img class="header-hero-image" src="/assets/images/toolkit/toolkit-hero.svg">
In an img
HTML tag,
- Set
src
to the path to the SVG or image - Add an
alt
attribute with an appropriate descriptive text. (Depending on the image, thealt
attribute will either be an emptyalt
attribute (alt=""
) or will have an appropriate descriptive text. You can use this alt Decision Tree to help you decide what thealt
attribute should contain.)
<img class="header-hero-image" src="/assets/images/toolkit/toolkit-hero.svg" alt="" >
Example of an SVG wrapped in a div
tag that needs an ARIA label:
<div>
{% include svg/logo-hfla-small.svg %}
</div>
In an div
HTML tag,
- Add a
role="img"
- Add an
aria-label
with an appropriate descriptive text.
<div role="img" aria-label="Hack for LA">
{% include svg/logo-hfla-small.svg %}
</div>
Review the w3.org document about accessible names and descriptions here.
Naming:
- Naming with child content.
- Naming with a string attribute via aria-label.
- Naming by referencing content with aria-labelledby.
- Naming form controls with the label element.
- Naming fieldsets with the legend element.
- Naming tables and figures with captions.
- Fallback names derived from titles and placeholders.
Describing:
- Describing by referencing content with aria-describedby.
- Describing tables and figures with captions.
- Descriptions derived from titles.
Click the arrow below each category to view links (or view original alphabetical list by clicking "Pages" above) :