Label at Front

Link to Label at Front copied to clipboard
Free Trial

WCAG 2.1 - 2.5.3 Best Practice Impact - Minor

Any visible text of an interactive view should be at the start of the view's accessible name.

Impact

TalkBack users expect the accessible name announced first when interacting with a control. As a best practice, we recommend having a controls visible text within the name and all other information within the accessible value, hint, or role.

Confirmation

  1. Turn on TalkBack
  2. Focus the element
  3. One of the following will happen:
    • Inaccessible: TalkBack will announce other text before announcing the active control's text
    • Accessible: TalkBack will announce the active control's text first

How to Fix

An issue found by this rule is caused by the visible text missing from the start of the control's content description.

XML

For a provided button:

<Button
   android:id="@+id/email_button"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_marginTop="@dimen/xlg"
   android:text="Send"
   app:layout_constraintStart_toStartOf="parent"
   app:layout_constraintEnd_toEndOf="parent"
   app:layout_constraintTop_toBottomOf="@id/divider2" />

Passing example:

val button = findViewById<Button>(R.id.email_button)
button.contentDescription = "Send Email"

Failing example: Note the visible text is not available at the start of the content description.

val button = findViewById<Button>(R.id.email_button)
button.contentDescription = "Tap to Send Email"

Compose

Passing example:

Text(modifier = Modifier.semantics { contentDescription = "Send Email" }, text = "Send")

Failing example: Note the visible text is not available at the start of the content description.

Text(modifier = Modifier.semantics { contentDescription = "Click to Send" }, text = "Send")

React Native

The accessibilityLabel property should start with the component's visible text.

By default, a button will use its title as its accessibilityLabel, and will therefore pass this rule.

<Button 
   title={'Menu'}
   mode='contained'
   accessibilityLabel='Menu'
/>

If you choose to customize the accessibilityLabel for a button, ensure it starts with the text of the title.

<Button 
   title={'Log In'}
   mode='contained'
   accessibilityLabel='Log In to Transfer Money'
/>
For other components without an explicit title, or when setting the `accessibilityLabel` explicitly, ensure that the `accessibilityLabel` begins with the component's visible text.
```jsx
<View style={styles.container}>
   <Button title='Menu' accessibilityLabel='Menu: Tap to Open'>
</View>