requires images to have alt text (wcag/h37)

Both HTML5 and WCAG 2.1 requires images to have a alternative text for each image. Decorative images must use empty (null) alt="" attribute.

Rule details

Examples of incorrect code for this rule:

error: <img> is missing required alt attribute (WCAG/H37) at inline:1:2:
> 1 | <img>
    |  ^^^

1 error found.

Examples of correct code for this rule:

<img alt="...">


This rule takes an optional object:

    "allowEmpty": true,
    "alias": []

allow empty

Sometimes images are used in context where the image only adds to the user experience but is already clear from an A17Y perspective.

When true this allows empty <img alt=""> to be used to prevent errors and to signal that the image is not ment to be read.

Examples of correct code for this rule:

<span>The task was successfully completed! <img src="thumbsup.png" alt=""></span>


If javascript is used to set the attribute on-the-fly (e.g. using angular-translate) the alternative attributes can be listed here.

Examples of correct code when alias is ["data-alt"]:

<img data-alt="...">