Explicit label
• Add the for attribute for the label element. The attribute value is consistent with the ID attribute value of the Form Control.
• Reset and submit buttons (<input type = "reset"/>, <input type = "Submit"/>), and image buttons (<input type = "IMG"/>) and the script button (<button> </button>) do not use an explicit label, because they already have an implicit label, such as the value and ALT attribute values, and the content of the button element.
<Label for = "firstname"> First name: </label> <input type = "text" name = "firstname" id = "firstname" tabindex = "1"/>
Implicit label
• According to the HTML 4.01 standard, you can use the label element to wrap Form Controls and label text to create an "implicit label ".
• Some browsers (IE6) do not support implicit label, which is not recommended for wcag2.0.
<Label> First name: <input type = "text" name = "firstname"/> </label>
Another method is the combination of the above two methods:
<Label for = "firstname"> First name:
<Input type = "text" name = "firstname" id = "firstname" tabindex = "1"/> </label>
Differences between the two
The screen reader nvda and ie9 test shows that the content prompted by the Screen Reader user is different:
• Explicit label: "ffirst name: blank edit box (or content )"
• Implicit label Syntax: "First name: Text first name: blank edit box (or content)"-the two methods are consistent, however, the last method cannot activate the form control when you click label in all browsers (I have changed it by mistake in the demo). This method is strongly not recommended.
As you can see, nvda repeats the label text content, making it easier for screen reader users to understand the prompts for explicit label writing.
View demo
Update: HTML5 accessibility chops: Form control labeling
Http://www.html5accessibility.com/tests/form-labels.html)
After the same test, the author tested more browsers and screen readers, checked the test demo page and result page, and obtained the same conclusion: using for and ID, and the form control is not placed in the label element is the most robust method.