invalid-labeling-attribute

Ensure that you are using only valid labeling attributes or methods .

Who might be affected
Screen Reader
Voice Control

Description

Text input fields usually require specific labeling attributes or methods to correctly announce both the label (accessible name) and the value, so they are understandable for all users.

Quick Fixes

When using an ImageView, ImageButton, CheckBox, or other View that conveys information graphically, use an android:contentDescription attribute to provide a content label for that View. For EditTexts or editable TextViews, use an android:hint attribute to indicate the purpose of the text field. An android:contentDescription should not be used as a content label for editable Views.

Android (.xml):

Pass

1<EditText
2 android:id="@+id/firstNmaeField"
3 android:layout_width="match_parent"
4 android:layout_height="wrap_content"
5 android:hint="First Name"/>
1<LinearLayout
2 android:layout_width="match_parent"
3 android:layout_height="match_parent"
4 android:orientation="vertical">
5 <TextView
6 android:layout_width="match_parent"
7 android:layout_height="wrap_content"
8 android:text="First Name"
9 android:labelFor="@id/firstNmaeField" />
10 <EditText
11 android:id="@+id/firstNmaeField"
12 android:layout_width="wrap_content"
13 android:layout_height="wrap_content" />
14</LinearLayout>
1<AutoCompleteTextView
2 android:id="@+id/foodSelectCombo"
3 android:layout_width="match_parent"
4 android:layout_height="wrap_content"
5 android:hint="What is your favorite food?"/>

Fail

1<EditText
2 android:id="@+id/firstNmaeField"
3 android:layout_width="match_parent"
4 android:layout_height="wrap_content"
5 android:contentDescription="First Name"/>
1<AutoCompleteTextView
2 android:id="@+id/foodSelectCombo"
3 android:layout_width="match_parent"
4 android:layout_height="wrap_content"
5 android:contentDescription="What is your favorite food?"/>

Android (Java):

Pass

1EditText editText = new EditText(this);
2 editText.setHint("First Name");
1TextView label = new TextView(this);
2 label.setText("First Name");
3
4 EditText editText = new EditText(this);
5
6 label.setLabelFor(editText.getId());

Fail

1EditText editText = new EditText(this);
2 editText.contentDescription("First Name");

How Users Are Affected

Some assistive technologies, especially screen readers, may read the label differently or out of order, so users may not understand it accurately and sometimes may not hear it at all.

WCAG Success criteria

4.1.1 parsing (A)