Estimated reading time: ( words)
Summary: You should add appropriate alternative text to every image, regardless of how it is coded. The alt text should describe the content or function of the image. Purely decorative images should have empty alt text.
Always include an alt attribute for images that are displayed using the image tag.
If the image is decorative, the alt attribute should be empty, like this:
The difference between an empty alt attribute and no alt attribute at all is that the empty attribute lets screen reader users know that an image is there.
Avoid context-redundant alternative text
Sometimes information about the image is displayed as part of the normal text surrounding the image, either as part of the narrative or as an image caption. In this case, include an empty alt attribute so the alternative text is not read or displayed twice by adaptive technologies like screen readers. A blank alt attribute looks like this:
The CSS background property is often used to display images. You still need appropriate alternative text but needs to be done with “plain” text (text that is contained in the code and not in an image tag). In this case, the alt text should only be exposed to screen reader users, using the .sr-only class.
/* Items with this class will only be available to screen reader users */
width:1px; /* do not set to 0 */
height:1px; /* do not set to 0 */
The .sr-only class already exists if you are using Bootstrap version 3 or higher.
Here's an example of a CSS-based image where the alt text is only available to screen reader users:
<span class=”sr-only”> Goldy Gopher </span> <!-- alternative text -->
While extremely handy for developers, font icons like Font Awesome or Glyphicons can pose accessibility issues.
- Screen readers may read font icons as nonsensical text
- Persons using an adaptive technology to override the font-family (for example, users with dyslexia) may see font icons as empty boxes
The first issue can be addressed with HTML. The icon itself can be hidden from screen reader users by using the ARIA-hidden="true" attribute, which looks like this:
<i class=”fa fa-flag”></i>
You must add the aria-hidden-”true” attribute to the parent of the font icon and not to the font icon itself. Then, you can use alt text exposed only to screen reader users by using the CSS, class shown above.