Provide prompt text for each form item
Screen reader users need to hear what the purpose of each form field is so each form item needs to be appropriately labeled with prompt text next to it. Here's an example of a form item with the prompt text, ‘Name’:
With regards to the checkboxes and radioboxes, ‘Hobbies’ and ‘Birthday’ aren't prompt text; the words directly adjacent to the boxes are (i.e. ‘Sport’, ‘Music’ etc.).
Be careful though, just because it looks like text is positioned correctly, it may not be within the HTML code. Check your HTML code (or get someone else to) to ensure that the appropriate text comes immediately before input boxes, textareas and dropdown boxes and immediately after checkboxes and radioboxes.
Label prompt text
Now we've got our prompt text set up and positioned correctly, we now need to assign it to its form item. This can be simply achieved using the <label> tag. For a regular input box this would look like:
<label for="name">Name</label> <input type="text" id="name" />
For a checkbox this would look like:
<input type="checkbox" id="sport" /> <label for="sport">Sport</label>
Essentially it's irrelevant what value you put into the <label for> tag, provided it's the same as the id in the input item and that it's unique across the page.
There's a very simple way to test for this on any website: If the prompt text has been assigned to the form item then when you click on the text the form item should become focused. With a text box, this means a flashing cursor will appear in the box; with a checkbox, the box itself will become selected - check this out with the form above!
Title form items with no prompt text
Occasionally, it is impossible to assign prompt text, even invisible prompt text, to a form item. In this case, you can use the title attribute, which now gets read out by most modern screen readers. Using the example of the search function again, you would use the following HTML code:
<input type="text" title="search" /> <input type="button" value="search" />
As the title attribute isn't well supported by older screen readers, this technique should only be used on those rare occasions where there's no other choice available.
Conclusion
Applying basic accessibility isn't particularly difficult. if you look at your website now, chances are that prompt text is already present, and more often than not it's positioned correctly. Add a few labels to the prompt text and you'll be good to go!
Read part 2 of this article, which will show you some more ways of making your forms accessible.
This article was written by Trenton Moss, founder of Webcredible, a web usability and accessibility consultancy. He's extremely good at usability testing and likes to offer CSS help whenever he can.