Technique H44:Using label elements to associate text labels with form controls
Applicability
HTML and XHTML controls that use external labels
This technique relates to:
- 1.1.1: Non-text Content (Sufficient)
- 1.3.1: Info and Relationships (Sufficient when used with Making information and relationships conveyed through presentation programmatically determinable using the following techniques: )
- 3.3.2: Labels or Instructions (Sufficient)
- 4.1.2: Name, Role, Value (Sufficient when used with G108: Using markup features to expose the name and role, allow user-settable properties to be directly set, and provide notification of changes)
Description
The objective of this technique is to use the label element to explicitly
                  associate a form control with a label. A label is attached to a specific
                  form control through the use of the for attribute. The value of the
                  for attribute must be the same as the value of the id
                  attribute of the form control. 
The id attribute may have the same value as the name
                  attribute, but both must be provided, and the id must be unique in the Web
                  page.
This technique is sufficient for Success Criteria 1.1.1, 1.3.1 and 4.1.2 whether or
                  not the label element is visible. That is, it may be hidden using CSS. However, for Success Criterion
                  3.3.2, the label element must be visible since it provides assistance to all users who need help understanding
                  the purpose of the field. 
An additional benefit of this technique is a larger clickable area for the control, since clicking on the label or the control will activate the control. This can be helpful for users with impaired motor control.
Note that the label is positioned after input elements of
                  
                  							type="checkbox" and 
                  							type="radio".
Elements that use explicitly associated labels are:
- 
                        									         
                        										inputtype="text"
- 
                        									         
                        										inputtype="checkbox"
- 
                        									         
                        										inputtype="radio"
- 
                        									         
                        										inputtype="file"
- 
                        									         
                        										inputtype="password"
- 
                        									         textarea
- 
                        									         select
The label element is not used for the following
                     because labels for these elements are provided via the value attribute (for Submit
                     and
                     Reset buttons), the alt attribute (for image buttons), or element content itself
                     (button). 
- Submit and Reset buttons (
                        										inputtype="submit" orinputtype="reset")
- Image buttons (
                        										inputtype="image")
- Hidden input fields (
                        										inputtype="hidden")
- Script buttons (buttonelements or <inputtype="button">)
Examples
Example 1: A text input field
The text field in the example below has the explicit label of "First name:". The
                     label element's for attribute matches the
                     id attribute of the input element. 
<label for="firstname">First name:</label> <input type="text" name="firstname" id="firstname" />
Example 2: A checkbox
<input type="checkbox" id="markuplang" name="computerskills" checked="checked"> <label for="markuplang">HTML</label>
Example 3: A group of radio buttons
A small, related group of radio buttons with a clear description and labels for each individual element.
To provide clear associations and instructions for a large set of related radio buttons , should be considered.
 <h1>Donut Selection</h1>
<p>Choose the type of donut(s) you would like then select 
   the "purchase donuts" button.</p>
<form action="http://example.com/donut" method="post">
<p>
  <input type="radio" name="flavor" id="choc" value="chocolate" />
    <label for="choc">Chocolate</label><br/>
  <input type="radio" name="flavor" id="cream" value="cream"/>
    <label for="cream">Cream Filled</label><br/>
  <input type="radio" name="flavor" id="honey" value="honey"/>
    <label for="honey">Honey Glazed</label><br/>
  <input type="submit" value="Purchase Donuts"/>
</p>
</form>
               Other sources
No endorsement implied.
Tests
Procedure
For all input elements of type text, file or
                     password, for all textareas and for all
                     select elements in the Web page: 
- Check that there is a labelelement that identifies the purpose of the control before theinput,textarea, orselectelement
- Check that the forattribute of thelabelelement matches the id of theinput,textarea, orselectelement
- Check that the labelelement is visible.
For all input elements of type checkbox or radio in the Web page:: 
- Check that there is a labelelement that identifies the purpose of the control after theinputelement
- Check that the forattribute of thelabelelement matches theidof theinputelement
- Check that the labelelement is visible.
Expected Results
- Checks #1 and #2 are true. For Success Criterion 3.3.2, Check #3 is also true.