screenshot of image widget form with the new "decorative" checkbox checked

This module provides a solution for site builders that want to make the option of leaving an image's alternative text blank explicit (by checking a new "Decorative" checkbox) rather than implicit (by simply leaving the alt text field blank).

In other words, editors are forced to affirm that the reason they're leaving alt text empty is because the image is decorative and should be hidden from screen readers.

If the new "Decorative" checkbox is not checked and no alt text is provided, the form will fail validation.

How to Use

  1. Enable the module.
  2. Edit an image field and make sure alt text is enabled and NOT required.
  3. Edit the form display settings for the image and enable the option to force the image to be marked decorative when no alt text is provided.*
  4. Add an image and observe you users cannot leave alt text blank without checking the "Decorative" checkbox.

*Assumes your selected form widget is the one provided by core, or one that extends it.

Features

  1. Adds a "Decorative" checkbox to image widgets that must be checked if the user wants to leave the alt text empty.
  2. Forces users to stop and think about alternative text rather than leaving it blank.
  3. Works with any existing image widget that extends from core's default. For example, you can use this with the default image widget or the one provided by Image Widget Crop.
  4. Does not require any data model changes - the state of the "Decorative" checkbox is inferred entirely from the value of the alt text.

A note on Media module usage

Most Drupal 8 and newer sites are using core's Media and Media Library modules, which decouple images from the entity (e.g. a content type), allowing the same media to be used in many places on your site by reference.

It's important to keep in mind that good alternative text varies depending on the context it is used. A content author should describe a picture of fireworks differently when displayed in an article about photography techniques vs an article about the event in general.

As such, while this module works just fine with the Media module, it's best not to rely on it if your site uses the same image in multiple different contexts, as you won't be able to change the alt text per context.

Further Reading

There is an effort to make similar functionality available in Drupal core: #2934405: [META] Improve workflows for image alternative text

Project information

Releases