Success Criterion 4.1.2 Name, Role, Value: [Level A]
Techniques
The terms name, role and value as used by W3C may not be what you think they mean. The following table, courtesy of W3C, sheds some light on these terms and also how they are applied to the afore-mentioned form controls.
| HTML element | Role | Name | Value | State |
|---|---|---|---|---|
| <a> | link | 'title' attribute, text within <a> element or 'alt' attribute if image link. Concatenated if both text and image 'alt' attribute are provided | 'href' attribute | |
| <button> | push button | text inside <button> element or 'title' attribute | ||
| <fieldset> | grouping | <legend> element | ||
| <input type = "button", "submit", or "reset"> | push button | 'value' attribute | ||
| <input type = "image"> | push button | 'alt' attribute or 'title' attribute | ||
| <input type = "text"> | editable text | <label> element associated with it or 'title' attribute | 'value' attribute | |
| <input type = "password"> | editable text | <label> element associated with it or 'title' attribute | ||
| <input type="checkbox"> | checkbox | <label> element associated with it or 'title' attribute | 'checked' attribute | |
| <input type="radio"> | radio button | <label> element associated with it or 'title' attribute | 'checked' attribute | |
| <select> | combobox, list, or dropdown list | <label> element associated with it or 'title' attribute | <option> element with 'selected' attribute set to "selected" | |
| <textarea> | editable text | <label> element associated with it or 'title' attribute | text within <textarea> element |
G198: Using markup features to expose the name and role
The markup for any control, custom or otherwise, must be done in such a way that the control's name and/or role can be identified by assitive technology. In the case where content is created by programmatical means, the technology used must interface with the assitive technology's APIs. Use standard HTML form controls and link elements to provide keyboard operation and assistive technology interoperability of interactive user interface elements. It can be broken down into the following techniques.
H91: Using markup features and HTML controls and links
A standard link is coded as follows:
If an image is used as the name instead of text, this must be provided by the alt attribute:
If an image and text is required, the 'alt' text and the name text will normally be concatenated. In the following example the link will be read as "Website Link":
For buttons, the name is provided by the value attribute or the text content:
If an image button is required however, the name must be obtained from using an alt attribute.
If there is no alt attribute, the title attribute will be used. In the case of both being present, the alt takes precedence. If both alt and title are omitted then this is an example of where the criteria would fail, any assitive technology being unable to resolve the name.
The label tag is used to associate a name to a control.
<input id="text_field_1" type="text" value="qwerty" />
In the absence of a label tag the name is taken from the title attribute.
H44: Using label elements to associate text labels with form controls
The use of explicit and implicit labels are in the HTML and XHTML specifications. However some screen readers have a problem reading implicit labels and it is recommended to always use an explicit label for a form control.
The label is associated to the control by the for attribute which must match the control's id value. Although the name attribute may not necessarily match the id both must be present. An additional benefit of providing a label is that this will also be clickable and thereby increase the clickable area for that control. Note that labels are not used for any kind of button control as the name will be taken from the value attribute.
Note:
For checkboxes and radio buttons, the label tag should follow the control.
For a group of checkboxes and radio buttons a label tag should be provided for each control.
<input type="radio" name="sex" id="f" /><label for="f">Female</label>
<input type="radio" name="sex" id="h" /><label for="h">Hermaphrodite</label>
A common mistake is to omit a label for a drop down list. It can be applied to the select element.
<select name="islands" id="islands">
<option value="" selected="selected" >Select an island ...</option>
<option value="B">Barbados</option>
<option value="J">Jamaica</option>
<option value="A">Antigua</option>
<option value="T">Trinidad</option>
</select>
H65: Using the title attribute to identify form controls when the label element cannot be used
In some cases it is not possible to use a label tag. There may be no text on the screen that could be identified as a label or it might be confusing to actually display one. In these cases the 'title' attribute should be used.
Take the case of a typical text box where a search item may be enterered immediately followed by a search button. In this case it evident from the visual display that items are typed in the box prior to the search button being clicked. Screen readers do not have this advantage so we must indicate what the use of the text box is.
Another common use might be where an input field is split in to multiple text boxes, for instance a telephone number
Please note that this is only one possible format of a British phone number.
H88: Using HTML according to spec
This basically means that HTML or XHTML should be used according to their specifications. It should be used semantically and follow any guidance given.
Failures
F59: Using scripting to make div or span a user interface control in HTML
In this example, different images are being used for a ticked and an unticked checkbox. A span element with a JavaScript event on it is being used to toggle the image. Any assitive technology would not be able to identify this as a form control.
<img src="unchecked.gif" id="chkbox" alt=""> Agree to terms and conditions
</span>
F20: Text alternatives not updated when non-text content is changed.
An example of this might be where a picture on a page changes daily but the text alternative is not kept in step with the picture being shown.
F68: label not properly associated with a form control
Because label elements have not been used to associate the 'label' text shown with a particular control, assitive technologies may not be able to determine which label goes with which control in the following example.
<input type="text" name="firstname">
Last name:
<input type="text" name="lastname">
Male: <input type="radio" name="sex" value="male" />
Female: <input type="radio" name="sex" value="female" />
A label element may have been used but if it does not explicitly reference the control assitive technologies may still be unable to determine which label with which control.
<input type="text" name="firstname">
<label>Last name:</label>
<input type="text" name="lastname">
<label>Male:</label> <input type="radio" name="sex" value="male" />
<label>Female:</label> <input type="radio" name="sex" value="female" />
A similar example would be where implicit labels have been used.
<label>Last name: <input type="text" name="lastname"></label>
<label>Male: <input type="radio" name="sex" value="male" /></label>
<label>Female: <input type="radio" name="sex" value="female" /></label>
In those situations where it is not possible to use a label element, the title attribute must be used instead. If it is not present the name of the control cannot be established. This only applies to the text box in the following example as a name is associated to a button by its value.
F86: Not providing names for each part of a multi-part form field
For multi-part form fields, each part must be identified. Failure to do this results in failure of the criterion.
A label is supplied but is not assoicated with any of the parts.
A label is supplied but is associated with the first part of the field leaving the remaing two parts anonymous.
<input id="country" type="text" size="3" /> <input id="area" type="text" size="5" /> <input id="subscriber" type="text" size="6" />
F89: Using null alt on an image where the image is the only content in a link
This occurs when a link contains only non-text content, such as an image, and the non-text content has been implemented in a way that it can be ignored by assistive technology. In the following example two links are provided to navigate to the same page. However the first one is only an image with no text content and consequently screen readers may produce confusing rsults at this juncture.
This should have been coded conbining the text and the image