Checkboxes element missing "required" attribute

Created on 7 March 2018, over 7 years ago
Updated 18 August 2025, 7 days ago

Problem/Motivation

The checkboxes element provided by core does not apply the `required` attribute to the generated <input> elements. Instead the required attribute is applied to the wrapping <fieldset>.

There are two issues with this:

  1. screen readers use `required` attribute on <input>s for checkboxes. If the attribute is not present on the <input>, then the required state will not be communicated to the screen reader user.
  2. the `required` attribute is not valid when applied to a <fieldset>, thus causing the page to fail W3C validation.

To reproduce this, create a form that uses the Checkboxes element. Notice that the required attribute is attached to the wrapping <fieldset> and not the <input> elements.

@mfairchild365 created a hacky module to fix the issue. It might be helpful in diagnosing and fixing the issue in core: https://github.com/mfairchild365/a11yformsfix/blob/master/readme.md

Proposed resolution

  1. Minimum: avoid the invalid HTML - remove the required attribute from the fieldset element.
  2. Ideally: figure out a good approach to improve the checkboxes, and convey the requirements to assistive tech. Mandatory checkboxes mean "tick at least one of these", which isn't easily expressed by HTML.

Remaining tasks

Evaluate impact on templates - does this qualify as a bugfix which can go in Stable theme?
Write a patch.
Tests?

User interface changes

Markup changes to:

  1. Fix invalid HTML
  2. Convey required checkboxes element correctly to assistive tech.

API changes

None.

Data model changes

none.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

render system

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia acbramley

    This is still valid on HEAD, tested with the default options checkboxes on the NodeTypeForm. AFAICT there is still no solution for this in raw HTML.

Production build 0.71.5 2024