Radio button accessibility (508 compliance)
Asked Answered
W

3

5

If I want to have a question with a "Yes/No" radio button. How do I need to mark up the code so that a screen reader reads the question associated with the "yes/no" selection instead of just reading the "Yes" and "No" labels when the radio buttons are selected?

<span>Did you understand this? (choose one) </span>
<label>
<input type="radio" id="yes_no" name="yes_no" value="Yes" />
Yes
</label>
<label>
<input type="radio" id="yes_no" name="yes_no" value="No" />
No
</label>

Thanks

Washy answered 10/6, 2010 at 17:45 Comment(0)
D
10

For form elements of this nature I use:

<fieldset>
  <legend>Did you understand the question?</legend>
  <input type="radio" name="yes_no" id="yes">
  <label for="yes">Yes</label>
  <input type="radio" name="yes_no" id="no">
  <label for="no">No</label>
</fieldset>

Also please take note that all ID values on a page should be unique. If you have an element that needs to share a descriptor then add it as a class.

I also use Fieldsets to add a distinct boundary to the radio selection.

And be sure to specify the for="id_value" attribute of the label. This will associate the label with the desired radio button.

Digitalin answered 10/6, 2010 at 18:1 Comment(1)
what about the tabindex? you'll get dinged on that by the ADA for sureArsenite
G
2
<fieldset>
<legend><span>Did you understand this? (choose one) </span></legend>
<label>
<input type="radio" id="yes_no" name="yes_no" value="Yes" />
Yes
</label>
<label>
<input type="radio" id="yes_no" name="yes_no" value="No" />
No
</label>
</fieldset>
Game answered 10/6, 2010 at 17:57 Comment(0)
L
-1

use the content attribute (if it is available).

Lotti answered 10/6, 2010 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.