Create accessible formatter using <figure> and <figcaption> tags for captions (a11y compliance)

Created on 7 September 2025, 7 days ago

Problem/Motivation

The current template does not follow the correct semantic structure for captions, as described in the following accessibility guidelines:
- https://stevenmouret.github.io/web-accessibility-guidelines/accessibilit...
- https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/fig...

To improve accessibility, captions should be wrapped in a <figure> element with a corresponding <figcaption>.

We need to either:
- create a new formatter that uses the proper template, or
- add an additional option to the existing formatter.

In both cases, we must ensure backward compatibility with the current implementation.

Steps to reproduce

1. Enable the module.
2. Enable the image caption option.
3. Inspect the rendered Twig output.
- Observe that the caption is not wrapped in a semantic `` / `` structure.

Proposed resolution

- Create an accessible image formatter that uses the semantic `` and `` structure for captions.
- Ensure the new formatter (or formatter option) follows WCAG and HTML5 accessibility recommendations.
- Maintain backward compatibility by:
- Keeping the existing formatter behavior unchanged by default.
- Providing the new accessible option as an alternative, or as an additional formatter.
- Add/update Twig templates to output `` and `` consistently with Drupal core patterns.
- Include automated and manual tests to confirm the new structure is applied and accessible.

User interface changes

- A new formatter option will be available, or alternatively a boolean setting will be added to the existing formatter.
- By default, the accessible `/` output will be disabled to avoid breaking existing implementations.
- Site builders can enable the option when they want captions to follow the accessible semantic structure.

📌 Task
Status

Active

Version

4.0

Component

Code

Created by

🇺🇦Ukraine Foxy-vikvik

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024