Success Criterion 3.3.2 - Level A
Labels or Instructions
Ensure clear instructions are provided in places users have to input data. Add a label to the input fields, for example 'First name'. Mark whether fields are required or optional. Indicate if data must be entered in a specified order. All users benefit from clear instructions. Clear instructions are indispensable for users with cognitive impairments.
Impact
Clear instructions make entering data more user-friendly for everyone.
Clear instructions are indispensable for users with cognitive, language and learning disabilities.
Check
“Is it clear which data is expected, and which fields are required, inside a forms?”
This can be tested without assistive technologies.
Solution
Use input labels
On Android, you can link labels to controls by using the labelFor
attribute. We recommend using a TextView
to show labels for input fields.
You can also use TextInputLayout
, which allows you to create an input field with a label. The hint
property at the TextInputLayout
level is used as visual label
. The hintEnabled
and expandedHintEnabled
properties must be set to true
to always show the label.
<TextView android:text="Name" android:labelFor="@+id/field"/>
<EditText id="@+id/field" hint="Enter your name"/>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="true"
app:expandedHintEnabled="true"
android:hint="Name">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your name"/>
</com.google.android.material.textfield.TextInputLayout>
Provide input instructions
On Android, you can use a TextView
to show instructions.
You can also use a TextInputLayout
, which contains a setHelperText
method to provide instructions. To show instructions, you need to set setHelperTextEnabled
to true
.
input.setHelperTextEnabled(true)
input.setHelperText("Your password should be at least 8 characters.")