Using grouping roles to identify related form controls

From WCAG WG


Status

Title

Using the “group” role to group a logical set of fields that can be referenced by a common label within a form.

Applicability

This technique applies to HTML with WAI-ARIA.

This technique relates to:

  • Success Criterion 1.3.1 (Info and relationships)
  • Success Criterion 3.3.2 (Labels or Instructions)

User Agent Issues

This technique works with:

  • JAWS 13 / 14 with Internet Explorer 8 / 9, Firefox
  • NVDA 2012 / 2013 with Firefox
  • VoiceOver with Safari on OSX 10.7.4 on MacBook Pro but not on later versions like OSX 10.8. (This has been reported to Apple along with broken support for the HTML "title" attribute)

Description:

The objective of this technique is to mark up a set of related controls within a form as a group. Any label associated with the group also serves as a common label or qualifier for individual controls in the group. Assistive technologies can indicate the start and end of the group and the group’s label as one navigates into and out of the group. This is a viable alternative for grouping form controls programmatically when the user interface’s design makes it difficult to employ the fieldset-legend technique (H71).

For a group of radio buttons, one could also use role="radiogroup" instead of role="group".

The group can be labeled using aria-labelledby.

This technique is not meant for wrapping all controls on a form within a single container with role="group".

Examples:

Example 1:

Social security number fields which are 9 digits long and broken up into 3 segments can be grouped using role="group".

Example code

<div role="group" aria-labelledby="ssn1">
   <span id="ssn1">Social Security#</span> 
   <span style="color: #D90D0D;"> * </span>
   <input size="3" type="text" aria-required="true" title="First 3 digits" />-
   <input size="2" type="text" aria-required="true" title="Next 2 digits" />-
   <input size="4" type="text" aria-required="true" title="Last 4 digits" />
</div>

View Example

Example 2:

This example demonstrates use role=radiogroup . Note also that the radio buttons are custom controls with role=radio. (But the script to make the span actually work like radio buttons is not included in this example. ) One may optionally employ CSS to place a border around groups of such fields to visually reinforce the group relationship. The CSS properties are available below the form.

<h3>Set Alerts for your Account</h3>
  <div role="radiogroup" aria-labelledby="alert1">
    <p id="alert1">Send an alert when balance exceeds $ 3,000</p>
    <div>
      <span role="radio" aria-labelledby="a1r1" name="a1radio"></span>
      <span id="a1r1">Yes</span>
    </div>
    <div>
      <span role="radio" aria-labelledby="a1r2" name="a1radio"></span>
      <span id="a1r2">No</span>
    </div>
  </div>
  <div role="radiogroup" aria-labelledby="alert2">
    <p id="alert2">Send an alert when a charge exceeds $ 250</p>
    <div>
      <span role="radio" aria-labelledby="a2r1" name="a2radio"></span>
      <span id="a2r1">Yes</span>
    </div>
    <div>
      <span role="radio" aria-labelledby="a2r2" name="a2radio"></span>
      <span id="a2r2">No</span>
    </div>
  </div>
  <p><input type="submit" value="Continue" id="continue_btn" name="continue_btn" /></p>

Related CSS Style Definition to place a border around the group of fields :

div[role=radiogroup] {
  border: black thin solid;
} 

Resources:

Related Techniques:

  • H71: Providing a description for groups of form controls using fieldset and legend elements

Tests

Procedure

For groups of related controls where the individual labels for each control do not provide a sufficient description, and an additional group level description is needed,

  • Check that the group of logically related input or select elements are contained within an element with role=group
  • Check that this group has an accessible name defined using aria-label or aria-labelledby

Expected Results

All of the above checks are true.