Skip to content
Gx
GitHub

GX2016: img has no alt attribute

An img element has no alt attribute, so a screen reader has no text for the image.

Cause

A user of a screen reader gets the alt text in the place of the image. An image with no alt attribute gives the file name, or nothing.

Gx gives no finding for an image with a spread, with role or with aria-hidden.

Example

team/Photo.gx
package team

<figure>
  <img src="/team.png" width="320" height="200">
  <figcaption>The team</figcaption>
</figure>

gx check reports:

gx check
team/Photo.gx:4:3: GX2016: the <img> has no alt attribute

Fix

  1. Write the text of the image: alt="Five people at a table".
  2. For an image that is only decoration, write alt="". A screen reader then ignores it.