Testing required on radio groups
A group of radio buttons can be a fieldset, a div with role="group", or a div with role="radiogroup". Only radiogroup supports aria-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.
HTML markup
<fieldset>
<legend>Which is your favourite pet?</legend>
<div>
<input type="radio" id="r1-dog" name="r1" value="dog">
<label for="r1-dog">Dog</label>
</div>
<div>
<input type="radio" id="r1-cat" name="r1" value="cat">
<label for="r1-cat">Cat</label>
</div>
<div>
<input type="radio" id="r1-rabbit" name="r1" value="rabbit">
<label for="r1-rabbit">Rabbit</label>
</div>
</fieldset>
Example 1.2: div with role="group"
Control: A div named with aria-labelledby. No requirement is defined.
HTML markup
<div role="group" aria-labelledby="r2-label">
<p id="r2-label">Which is your favourite pet?</p>
<div>
<input type="radio" id="r2-dog" name="r2" value="dog">
<label for="r2-dog">Dog</label>
</div>
<div>
<input type="radio" id="r2-cat" name="r2" value="cat">
<label for="r2-cat">Cat</label>
</div>
<div>
<input type="radio" id="r2-rabbit" name="r2" value="rabbit">
<label for="r2-rabbit">Rabbit</label>
</div>
</div>
Example 1.3: div with role="radiogroup"
Control: A div named with aria-labelledby. No requirement is defined.
HTML markup
<div role="radiogroup" aria-labelledby="r3-label">
<p id="r3-label">Which is your favourite pet?</p>
<div>
<input type="radio" id="r3-dog" name="r3" value="dog">
<label for="r3-dog">Dog</label>
</div>
<div>
<input type="radio" id="r3-cat" name="r3" value="cat">
<label for="r3-cat">Cat</label>
</div>
<div>
<input type="radio" id="r3-rabbit" name="r3" value="rabbit">
<label for="r3-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.
HTML markup
<fieldset>
<legend>Which is your favourite pet? (required)</legend>
<div>
<input type="radio" id="r4-dog" name="r4" value="dog">
<label for="r4-dog">Dog</label>
</div>
<div>
<input type="radio" id="r4-cat" name="r4" value="cat">
<label for="r4-cat">Cat</label>
</div>
<div>
<input type="radio" id="r4-rabbit" name="r4" value="rabbit">
<label for="r4-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.
HTML markup
<div role="group" aria-labelledby="r5-label">
<p id="r5-label">Which is your favourite pet? (required)</p>
<div>
<input type="radio" id="r5-dog" name="r5" value="dog">
<label for="r5-dog">Dog</label>
</div>
<div>
<input type="radio" id="r5-cat" name="r5" value="cat">
<label for="r5-cat">Cat</label>
</div>
<div>
<input type="radio" id="r5-rabbit" name="r5" value="rabbit">
<label for="r5-rabbit">Rabbit</label>
</div>
</div>
Example 2.3: div with role="radiogroup"
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.
HTML markup
<div role="radiogroup" aria-labelledby="r6-label">
<p id="r6-label">Which is your favourite pet? (required)</p>
<div>
<input type="radio" id="r6-dog" name="r6" value="dog">
<label for="r6-dog">Dog</label>
</div>
<div>
<input type="radio" id="r6-cat" name="r6" value="cat">
<label for="r6-cat">Cat</label>
</div>
<div>
<input type="radio" id="r6-rabbit" name="r6" value="rabbit">
<label for="r6-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.
HTML markup
<p>Required: Choose one pet.</p>
<fieldset>
<legend>Which is your favourite pet?</legend>
<div>
<input type="radio" id="r7-dog" name="r7" value="dog">
<label for="r7-dog">Dog</label>
</div>
<div>
<input type="radio" id="r7-cat" name="r7" value="cat">
<label for="r7-cat">Cat</label>
</div>
<div>
<input type="radio" id="r7-rabbit" name="r7" value="rabbit">
<label for="r7-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.
HTML markup
<fieldset aria-describedby="r8-hint">
<legend>Which is your favourite pet?</legend>
<p id="r8-hint">Choose one pet.</p>
<div>
<input type="radio" id="r8-dog" name="r8" value="dog">
<label for="r8-dog">Dog</label>
</div>
<div>
<input type="radio" id="r8-cat" name="r8" value="cat">
<label for="r8-cat">Cat</label>
</div>
<div>
<input type="radio" id="r8-rabbit" name="r8" value="rabbit">
<label for="r8-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.
HTML markup
<div role="group" aria-labelledby="r9-label" aria-describedby="r9-hint">
<h4 id="r9-label">Which is your favourite pet?</h4>
<p id="r9-hint">Choose one pet.</p>
<div>
<input type="radio" id="r9-dog" name="r9" value="dog">
<label for="r9-dog">Dog</label>
</div>
<div>
<input type="radio" id="r9-cat" name="r9" value="cat">
<label for="r9-cat">Cat</label>
</div>
<div>
<input type="radio" id="r9-rabbit" name="r9" value="rabbit">
<label for="r9-rabbit">Rabbit</label>
</div>
</div>
Example 4.3: div with role="radiogroup"
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.
HTML markup
<div role="radiogroup" aria-labelledby="r10-label" aria-describedby="r10-hint">
<h4 id="r10-label">Which is your favourite pet?</h4>
<p id="r10-hint">Choose one pet.</p>
<div>
<input type="radio" id="r10-dog" name="r10" value="dog">
<label for="r10-dog">Dog</label>
</div>
<div>
<input type="radio" id="r10-cat" name="r10" value="cat">
<label for="r10-cat">Cat</label>
</div>
<div>
<input type="radio" id="r10-rabbit" name="r10" value="rabbit">
<label for="r10-rabbit">Rabbit</label>
</div>
</div>
5. aria-required on the container
Only radiogroup supports aria-required. It is not supported on the group role.
Example 5.1: On the fieldset
Invalid: aria-required is not supported on the group role, which fieldset has implicitly.
HTML markup
<fieldset aria-required="true">
<legend>Which is your favourite pet?</legend>
<div>
<input type="radio" id="r11-dog" name="r11" value="dog">
<label for="r11-dog">Dog</label>
</div>
<div>
<input type="radio" id="r11-cat" name="r11" value="cat">
<label for="r11-cat">Cat</label>
</div>
<div>
<input type="radio" id="r11-rabbit" name="r11" value="rabbit">
<label for="r11-rabbit">Rabbit</label>
</div>
</fieldset>
Example 5.2: On the div with role="group"
Invalid: aria-required is not supported on the group role.
HTML markup
<div role="group" aria-labelledby="r12-label" aria-required="true">
<p id="r12-label">Which is your favourite pet?</p>
<div>
<input type="radio" id="r12-dog" name="r12" value="dog">
<label for="r12-dog">Dog</label>
</div>
<div>
<input type="radio" id="r12-cat" name="r12" value="cat">
<label for="r12-cat">Cat</label>
</div>
<div>
<input type="radio" id="r12-rabbit" name="r12" value="rabbit">
<label for="r12-rabbit">Rabbit</label>
</div>
</div>
Example 5.3: On the div with role="radiogroup"
Acceptable: radiogroup is the only group role that supports aria-required, so this exposes a required state to assistive technology. It adds nothing visible, so use it together with the group's name or a hint, not instead of them.
HTML markup
<div role="radiogroup" aria-labelledby="r13-label" aria-required="true">
<p id="r13-label">Which is your favourite pet?</p>
<div>
<input type="radio" id="r13-dog" name="r13" value="dog">
<label for="r13-dog">Dog</label>
</div>
<div>
<input type="radio" id="r13-cat" name="r13" value="cat">
<label for="r13-cat">Cat</label>
</div>
<div>
<input type="radio" id="r13-rabbit" name="r13" value="rabbit">
<label for="r13-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.
HTML markup
<fieldset required>
<legend>Which is your favourite pet?</legend>
<div>
<input type="radio" id="r14-dog" name="r14" value="dog">
<label for="r14-dog">Dog</label>
</div>
<div>
<input type="radio" id="r14-cat" name="r14" value="cat">
<label for="r14-cat">Cat</label>
</div>
<div>
<input type="radio" id="r14-rabbit" name="r14" value="rabbit">
<label for="r14-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.
HTML markup
<div role="group" aria-labelledby="r15-label" required>
<p id="r15-label">Which is your favourite pet?</p>
<div>
<input type="radio" id="r15-dog" name="r15" value="dog">
<label for="r15-dog">Dog</label>
</div>
<div>
<input type="radio" id="r15-cat" name="r15" value="cat">
<label for="r15-cat">Cat</label>
</div>
<div>
<input type="radio" id="r15-rabbit" name="r15" value="rabbit">
<label for="r15-rabbit">Rabbit</label>
</div>
</div>
Example 6.3: On the div with role="radiogroup"
Invalid: required is only valid on input, select and textarea. A role does not add HTML attributes.
HTML markup
<div role="radiogroup" aria-labelledby="r16-label" required>
<p id="r16-label">Which is your favourite pet?</p>
<div>
<input type="radio" id="r16-dog" name="r16" value="dog">
<label for="r16-dog">Dog</label>
</div>
<div>
<input type="radio" id="r16-cat" name="r16" value="cat">
<label for="r16-cat">Cat</label>
</div>
<div>
<input type="radio" id="r16-rabbit" name="r16" value="rabbit">
<label for="r16-rabbit">Rabbit</label>
</div>
</div>
7. Requirement on the radios
Attributes on the radio buttons themselves. Radios that share a name form one set.
None of these options is good practice.
Example 7.1: aria-required on each radio
Invalid: aria-required is not supported on the radio role.
HTML markup
<fieldset>
<legend>Which is your favourite pet?</legend>
<div>
<input type="radio" id="r17-dog" name="r17" value="dog" aria-required="true">
<label for="r17-dog">Dog</label>
</div>
<div>
<input type="radio" id="r17-cat" name="r17" value="cat" aria-required="true">
<label for="r17-cat">Cat</label>
</div>
<div>
<input type="radio" id="r17-rabbit" name="r17" value="rabbit" aria-required="true">
<label for="r17-rabbit">Rabbit</label>
</div>
</fieldset>
Example 7.2: aria-required on one radio only
Invalid: aria-required is not supported on the radio role, and one radio does not set a requirement for the group.
HTML markup
<fieldset>
<legend>Which is your favourite pet?</legend>
<div>
<input type="radio" id="r18-dog" name="r18" value="dog" aria-required="true">
<label for="r18-dog">Dog</label>
</div>
<div>
<input type="radio" id="r18-cat" name="r18" value="cat">
<label for="r18-cat">Cat</label>
</div>
<div>
<input type="radio" id="r18-rabbit" name="r18" value="rabbit">
<label for="r18-rabbit">Rabbit</label>
</div>
</fieldset>
Example 7.3: required on every radio
Poor practice: Native validation blocks submission until one radio is chosen. It relies on the browser's built-in message, which you can't word or style, and which only appears on submit.
HTML markup
<fieldset>
<legend>Which is your favourite pet?</legend>
<div>
<input type="radio" id="r19-dog" name="r19" value="dog" required>
<label for="r19-dog">Dog</label>
</div>
<div>
<input type="radio" id="r19-cat" name="r19" value="cat" required>
<label for="r19-cat">Cat</label>
</div>
<div>
<input type="radio" id="r19-rabbit" name="r19" value="rabbit" required>
<label for="r19-rabbit">Rabbit</label>
</div>
</fieldset>
Example 7.4: required on one radio only
Poor practice: Native validation treats the whole named set as required, but the attribute is on one radio only, so users of assistive technology may take it to mean that one radio is required, not the group. It relies on the browser's built-in message, which you can't word or style, and which only appears on submit.
HTML markup
<fieldset>
<legend>Which is your favourite pet?</legend>
<div>
<input type="radio" id="r20-dog" name="r20" value="dog" required>
<label for="r20-dog">Dog</label>
</div>
<div>
<input type="radio" id="r20-cat" name="r20" value="cat">
<label for="r20-cat">Cat</label>
</div>
<div>
<input type="radio" id="r20-rabbit" name="r20" value="rabbit">
<label for="r20-rabbit">Rabbit</label>
</div>
</fieldset>
8. Recommended practice
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.
HTML markup
<fieldset>
<legend>Which is your favourite pet? (required)</legend>
<div>
<input type="radio" id="r4rec-dog" name="r4rec" value="dog">
<label for="r4rec-dog">Dog</label>
</div>
<div>
<input type="radio" id="r4rec-cat" name="r4rec" value="cat">
<label for="r4rec-cat">Cat</label>
</div>
<div>
<input type="radio" id="r4rec-rabbit" name="r4rec" value="rabbit">
<label for="r4rec-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.
HTML markup
<div role="group" aria-labelledby="r5rec-label">
<p id="r5rec-label">Which is your favourite pet? (required)</p>
<div>
<input type="radio" id="r5rec-dog" name="r5rec" value="dog">
<label for="r5rec-dog">Dog</label>
</div>
<div>
<input type="radio" id="r5rec-cat" name="r5rec" value="cat">
<label for="r5rec-cat">Cat</label>
</div>
<div>
<input type="radio" id="r5rec-rabbit" name="r5rec" value="rabbit">
<label for="r5rec-rabbit">Rabbit</label>
</div>
</div>
Example 8.3: div with role="radiogroup"
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.
HTML markup
<div role="radiogroup" aria-labelledby="r6rec-label">
<p id="r6rec-label">Which is your favourite pet? (required)</p>
<div>
<input type="radio" id="r6rec-dog" name="r6rec" value="dog">
<label for="r6rec-dog">Dog</label>
</div>
<div>
<input type="radio" id="r6rec-cat" name="r6rec" value="cat">
<label for="r6rec-cat">Cat</label>
</div>
<div>
<input type="radio" id="r6rec-rabbit" name="r6rec" value="rabbit">
<label for="r6rec-rabbit">Rabbit</label>
</div>
</div>
Example 8.4: 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.
HTML markup
<fieldset aria-describedby="r8rec-hint">
<legend>Which is your favourite pet?</legend>
<p id="r8rec-hint">Choose one pet.</p>
<div>
<input type="radio" id="r8rec-dog" name="r8rec" value="dog">
<label for="r8rec-dog">Dog</label>
</div>
<div>
<input type="radio" id="r8rec-cat" name="r8rec" value="cat">
<label for="r8rec-cat">Cat</label>
</div>
<div>
<input type="radio" id="r8rec-rabbit" name="r8rec" value="rabbit">
<label for="r8rec-rabbit">Rabbit</label>
</div>
</fieldset>
Example 8.5: 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.
HTML markup
<div role="group" aria-labelledby="r9rec-label" aria-describedby="r9rec-hint">
<h4 id="r9rec-label">Which is your favourite pet?</h4>
<p id="r9rec-hint">Choose one pet.</p>
<div>
<input type="radio" id="r9rec-dog" name="r9rec" value="dog">
<label for="r9rec-dog">Dog</label>
</div>
<div>
<input type="radio" id="r9rec-cat" name="r9rec" value="cat">
<label for="r9rec-cat">Cat</label>
</div>
<div>
<input type="radio" id="r9rec-rabbit" name="r9rec" value="rabbit">
<label for="r9rec-rabbit">Rabbit</label>
</div>
</div>
Example 8.6: div with role="radiogroup"
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.
HTML markup
<div role="radiogroup" aria-labelledby="r10rec-label" aria-describedby="r10rec-hint">
<h4 id="r10rec-label">Which is your favourite pet?</h4>
<p id="r10rec-hint">Choose one pet.</p>
<div>
<input type="radio" id="r10rec-dog" name="r10rec" value="dog">
<label for="r10rec-dog">Dog</label>
</div>
<div>
<input type="radio" id="r10rec-cat" name="r10rec" value="cat">
<label for="r10rec-cat">Cat</label>
</div>
<div>
<input type="radio" id="r10rec-rabbit" name="r10rec" value="rabbit">
<label for="r10rec-rabbit">Rabbit</label>
</div>
</div>