This document is in beta. Help us by reporting issues via Github or email.
Form elements (like a text input field or a checkbox) should have clear labels and instructions.
On this page:
This ensures that everyone understands any requirements for entering data, and that screen reader users are made aware of it.
3.3.2 Labels or Instructions: Labels or instructions are provided when content requires user input. (Level A)
See the W3C’s detailed explanation of this guideline with techniques and examples.
placeholder
attribute doesn’t reliably provide input
elements with an ‘Accessible Name’.label
with an input
<label for="uname">Username:</label> <input type="text" id="uname" />
<!-- Don't do this -->
<div>
Username:
<input type="text" id="uname" />
</div>
aria-describedby
<label for="national-insurance-number">
National Insurance number
</label>
<span id="national-insurance-number-hint">
It’s on your National Insurance card, benefit letter, payslip or P60. For
example, ‘QQ 12 34 56 C’.
</span>
<input
id="national-insurance-number"
name="national-insurance-number"
type="text"
aria-describedby="national-insurance-number-hint national-insurance-number-error"
/>
<span id="national-insurance-number-error">
<span class="visually-hidden">Error:</span> Enter a National Insurance number
in the correct format
</span>
fieldset
with a legend
input type="checkbox"
and input type="radio"
elements that are related are grouped in a labelled container such as fieldset
with legend
.name
attribute.Correct use of name attribute ensures checking one radio button will uncheck the other:
<fieldset>
<legend>Would you like to receive email updates?</legend>
<input name="rg1" type="radio" id="r1" value="yes" />
<label for="r1">Yes</label>
<input name="rg1" type="radio" id="r2" value="no" />
<label for="r2">No</label>
</fieldset>
Incorrect use of the name attribute prevents correct keyboard access to radio buttons:
<!-- Don't do this -->
<input name="r1" type="radio" id="r1" value="yes" />
<label for="r1">Yes</label>
<input name="r2" type="radio" id="r2" value="no" />
<label for="r2">No</label>
Make sure that you closely follow the ‘Radio Group’ pattern in the ARIA Authoring Practices Guide, and test with one or more screen readers.
This document is in beta. Help us by reporting issues via Github or email.