Testing required on checkbox groups

There is no valid native HTML or ARIA way to mark a checkbox group as at least one required. The examples below show what each technique does and does not do.

Simplest approach: for any group of checkboxes or radios, add the requirement to the group's name, or add it as a hint. See Recommended practice.

Every example has a coloured box showing how to read it:

Invalid: not allowed by the HTML or ARIA specifications.

Poor practice: allowed, but not recommended.

Acceptable: allowed, and does part or all of the job. The box says what it does and does not give you.

Control: a baseline with no requirement defined.

1. Controls

Baselines with no requirement defined.

Example 1.1: fieldset

Control: A fieldset with a legend. No requirement is defined.

Which pets do you have?
HTML markup
<fieldset>
  <legend>Which pets do you have?</legend>
  <div>
    <input type="checkbox" id="c1-dog" name="c1" value="dog">
    <label for="c1-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c1-cat" name="c1" value="cat">
    <label for="c1-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c1-rabbit" name="c1" value="rabbit">
    <label for="c1-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 1.2: div with role="group"

Control: A div named with aria-labelledby. No requirement is defined.

Which pets do you have?

HTML markup
<div role="group" aria-labelledby="c2-label">
  <p id="c2-label">Which pets do you have?</p>
  <div>
    <input type="checkbox" id="c2-dog" name="c2" value="dog">
    <label for="c2-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c2-cat" name="c2" value="cat">
    <label for="c2-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c2-rabbit" name="c2" value="rabbit">
    <label for="c2-rabbit">Rabbit</label>
  </div>
</div>

2. Requirement as text in the group's name

The requirement is written in the visible text as part of the group's name: the legend, or the labelling element.

Example 2.1: fieldset

Acceptable: The requirement is in the group's accessible name, so it is available in text and associated with the group (WCAG 1.3.1 and 3.3.2). It does not expose a required state to assistive technology.

Which pets do you have? (required)
HTML markup
<fieldset>
  <legend>Which pets do you have? (required)</legend>
  <div>
    <input type="checkbox" id="c3-dog" name="c3" value="dog">
    <label for="c3-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c3-cat" name="c3" value="cat">
    <label for="c3-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c3-rabbit" name="c3" value="rabbit">
    <label for="c3-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 2.2: div with role="group"

Acceptable: The requirement is in the group's accessible name, so it is available in text and associated with the group (WCAG 1.3.1 and 3.3.2). It does not expose a required state to assistive technology.

Which pets do you have? (required)

HTML markup
<div role="group" aria-labelledby="c4-label">
  <p id="c4-label">Which pets do you have? (required)</p>
  <div>
    <input type="checkbox" id="c4-dog" name="c4" value="dog">
    <label for="c4-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c4-cat" name="c4" value="cat">
    <label for="c4-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c4-rabbit" name="c4" value="rabbit">
    <label for="c4-rabbit">Rabbit</label>
  </div>
</div>

3. Requirement as text outside the group

The requirement is written in the visible text outside the group.

Example 3.1: Text outside the group

Poor practice: The requirement is in a paragraph before the fieldset. Nothing associates it with the group.

Required: Choose at least one pet.

Which pets do you have?
HTML markup
<p>Required: Choose at least one pet.</p>
<fieldset>
  <legend>Which pets do you have?</legend>
  <div>
    <input type="checkbox" id="c5-dog" name="c5" value="dog">
    <label for="c5-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c5-cat" name="c5" value="cat">
    <label for="c5-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c5-rabbit" name="c5" value="rabbit">
    <label for="c5-rabbit">Rabbit</label>
  </div>
</fieldset>

4. Requirement as a hint

The requirement is a hint linked to the group with aria-describedby.

Example 4.1: fieldset

Acceptable: The hint is associated with the group with aria-describedby, so the requirement is available in text (WCAG 1.3.1 and 3.3.2). It does not expose a required state to assistive technology.

Which pets do you have?

Choose at least one pet.

HTML markup
<fieldset aria-describedby="c6-hint">
  <legend>Which pets do you have?</legend>
  <p id="c6-hint">Choose at least one pet.</p>
  <div>
    <input type="checkbox" id="c6-dog" name="c6" value="dog">
    <label for="c6-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c6-cat" name="c6" value="cat">
    <label for="c6-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c6-rabbit" name="c6" value="rabbit">
    <label for="c6-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 4.2: div with role="group"

Acceptable: The hint is associated with the group with aria-describedby, so the requirement is available in text (WCAG 1.3.1 and 3.3.2). It does not expose a required state to assistive technology.

Which pets do you have?

Choose at least one pet.

HTML markup
<div role="group" aria-labelledby="c7-label" aria-describedby="c7-hint">
  <h4 id="c7-label">Which pets do you have?</h4>
  <p id="c7-hint">Choose at least one pet.</p>
  <div>
    <input type="checkbox" id="c7-dog" name="c7" value="dog">
    <label for="c7-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c7-cat" name="c7" value="cat">
    <label for="c7-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c7-rabbit" name="c7" value="rabbit">
    <label for="c7-rabbit">Rabbit</label>
  </div>
</div>

5. aria-required on the container

aria-required is not supported on the group role, which fieldset has implicitly.

None of these options is valid.

Example 5.1: On the fieldset

Invalid: aria-required is not supported on the group role, which fieldset has implicitly.

Which pets do you have?
HTML markup
<fieldset aria-required="true">
  <legend>Which pets do you have?</legend>
  <div>
    <input type="checkbox" id="c8-dog" name="c8" value="dog">
    <label for="c8-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c8-cat" name="c8" value="cat">
    <label for="c8-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c8-rabbit" name="c8" value="rabbit">
    <label for="c8-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 5.2: On the div with role="group"

Invalid: aria-required is not supported on the group role.

Which pets do you have?

HTML markup
<div role="group" aria-labelledby="c9-label" aria-required="true">
  <p id="c9-label">Which pets do you have?</p>
  <div>
    <input type="checkbox" id="c9-dog" name="c9" value="dog">
    <label for="c9-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c9-cat" name="c9" value="cat">
    <label for="c9-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c9-rabbit" name="c9" value="rabbit">
    <label for="c9-rabbit">Rabbit</label>
  </div>
</div>

6. required on the container

required is an HTML attribute that is only valid on input, select and textarea. A role does not add HTML attributes.

None of these options is valid.

Example 6.1: On the fieldset

Invalid: required is only valid on input, select and textarea.

Which pets do you have?
HTML markup
<fieldset required>
  <legend>Which pets do you have?</legend>
  <div>
    <input type="checkbox" id="c10-dog" name="c10" value="dog">
    <label for="c10-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c10-cat" name="c10" value="cat">
    <label for="c10-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c10-rabbit" name="c10" value="rabbit">
    <label for="c10-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 6.2: On the div with role="group"

Invalid: required is only valid on input, select and textarea. A role does not add HTML attributes.

Which pets do you have?

HTML markup
<div role="group" aria-labelledby="c11-label" required>
  <p id="c11-label">Which pets do you have?</p>
  <div>
    <input type="checkbox" id="c11-dog" name="c11" value="dog">
    <label for="c11-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c11-cat" name="c11" value="cat">
    <label for="c11-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c11-rabbit" name="c11" value="rabbit">
    <label for="c11-rabbit">Rabbit</label>
  </div>
</div>

7. Requirement on the checkboxes

Attributes on the checkboxes themselves. Each checkbox is its own control, so a requirement on a checkbox applies to that checkbox only.

None of these options is good practice.

Example 7.1: aria-required on each checkbox

Poor practice: It marks every checkbox as required, which implies all of them must be ticked.

Which pets do you have?
HTML markup
<fieldset>
  <legend>Which pets do you have?</legend>
  <div>
    <input type="checkbox" id="c12-dog" name="c12" value="dog" aria-required="true">
    <label for="c12-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c12-cat" name="c12" value="cat" aria-required="true">
    <label for="c12-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c12-rabbit" name="c12" value="rabbit" aria-required="true">
    <label for="c12-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 7.2: aria-required on one checkbox only

Poor practice: It marks only that checkbox as required. It says nothing about the group.

Which pets do you have?
HTML markup
<fieldset>
  <legend>Which pets do you have?</legend>
  <div>
    <input type="checkbox" id="c13-dog" name="c13" value="dog" aria-required="true">
    <label for="c13-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c13-cat" name="c13" value="cat">
    <label for="c13-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c13-rabbit" name="c13" value="rabbit">
    <label for="c13-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 7.3: required on each checkbox

Poor practice: Native validation forces every checkbox to be ticked before the form submits.

Which pets do you have?
HTML markup
<fieldset>
  <legend>Which pets do you have?</legend>
  <div>
    <input type="checkbox" id="c14-dog" name="c14" value="dog" required>
    <label for="c14-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c14-cat" name="c14" value="cat" required>
    <label for="c14-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c14-rabbit" name="c14" value="rabbit" required>
    <label for="c14-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 7.4: required on one checkbox only

Poor practice: Native validation only forces that one checkbox to be ticked. It does not make the group require at least one.

Which pets do you have?
HTML markup
<fieldset>
  <legend>Which pets do you have?</legend>
  <div>
    <input type="checkbox" id="c15-dog" name="c15" value="dog" required>
    <label for="c15-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c15-cat" name="c15" value="cat">
    <label for="c15-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c15-rabbit" name="c15" value="rabbit">
    <label for="c15-rabbit">Rabbit</label>
  </div>
</fieldset>

The same examples as sections 2 and 4, repeated here so they are easy to find.

Example 8.1: fieldset

Acceptable: The requirement is in the group's accessible name, so it is available in text and associated with the group (WCAG 1.3.1 and 3.3.2). It does not expose a required state to assistive technology.

Which pets do you have? (required)
HTML markup
<fieldset>
  <legend>Which pets do you have? (required)</legend>
  <div>
    <input type="checkbox" id="c3rec-dog" name="c3rec" value="dog">
    <label for="c3rec-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c3rec-cat" name="c3rec" value="cat">
    <label for="c3rec-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c3rec-rabbit" name="c3rec" value="rabbit">
    <label for="c3rec-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 8.2: div with role="group"

Acceptable: The requirement is in the group's accessible name, so it is available in text and associated with the group (WCAG 1.3.1 and 3.3.2). It does not expose a required state to assistive technology.

Which pets do you have? (required)

HTML markup
<div role="group" aria-labelledby="c4rec-label">
  <p id="c4rec-label">Which pets do you have? (required)</p>
  <div>
    <input type="checkbox" id="c4rec-dog" name="c4rec" value="dog">
    <label for="c4rec-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c4rec-cat" name="c4rec" value="cat">
    <label for="c4rec-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c4rec-rabbit" name="c4rec" value="rabbit">
    <label for="c4rec-rabbit">Rabbit</label>
  </div>
</div>

Example 8.3: fieldset

Acceptable: The hint is associated with the group with aria-describedby, so the requirement is available in text (WCAG 1.3.1 and 3.3.2). It does not expose a required state to assistive technology.

Which pets do you have?

Choose at least one pet.

HTML markup
<fieldset aria-describedby="c6rec-hint">
  <legend>Which pets do you have?</legend>
  <p id="c6rec-hint">Choose at least one pet.</p>
  <div>
    <input type="checkbox" id="c6rec-dog" name="c6rec" value="dog">
    <label for="c6rec-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c6rec-cat" name="c6rec" value="cat">
    <label for="c6rec-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c6rec-rabbit" name="c6rec" value="rabbit">
    <label for="c6rec-rabbit">Rabbit</label>
  </div>
</fieldset>

Example 8.4: div with role="group"

Acceptable: The hint is associated with the group with aria-describedby, so the requirement is available in text (WCAG 1.3.1 and 3.3.2). It does not expose a required state to assistive technology.

Which pets do you have?

Choose at least one pet.

HTML markup
<div role="group" aria-labelledby="c7rec-label" aria-describedby="c7rec-hint">
  <h4 id="c7rec-label">Which pets do you have?</h4>
  <p id="c7rec-hint">Choose at least one pet.</p>
  <div>
    <input type="checkbox" id="c7rec-dog" name="c7rec" value="dog">
    <label for="c7rec-dog">Dog</label>
  </div>
  <div>
    <input type="checkbox" id="c7rec-cat" name="c7rec" value="cat">
    <label for="c7rec-cat">Cat</label>
  </div>
  <div>
    <input type="checkbox" id="c7rec-rabbit" name="c7rec" value="rabbit">
    <label for="c7rec-rabbit">Rabbit</label>
  </div>
</div>