Speaking form labels - Summary
Contents:
- Label hiding technique #1
- Label hiding technique #2
- Multiple labels
- Legend and fieldset
- Best practices
Some time ago, Joe Clark suggested “This, however, is a topic that should also be tested and written about.“
This series has its roots in WCAG 2.0 Guideline 4.2, Success Criteria #4, which states:
The label of each user interface control that accepts input from the user can be programmatically determined and is explicitly associated with the control. [I]
Note that “[I]” (invisible) indicates that a criterion does not specify how content should be presented. Apparently, that gave the green light to some WCAG contributors to find a way to hide labels whether it makes sense to do so or not. This led to the first two quizzes in this series.
Label hiding technique #1
The first quiz used an example from the CSS Techniques for WCAG 2.0. In that example, two techniques are described. My interest was drawn to the display:none technique. In earlier tests, we found that when display:none was used on other elements (headings, paragraphs, etc.) the screen reader usually did not speak those elements. Results from the 5.2.13 test case shows that some screen readers do indeed speak labels that are marked display:none. By the way, this still appears to be an open issue for the CSS Techniques document. The screen reader implementations demonstrate a level of inconsistency that I find absolutely confounding. Treating the attribute one way for some content and another for different content is beyond any standard, or any sense of logic. What happens when the day arrives that screen readers actually become standards compliant? If we have built sites based on these inconsistencies, it will be our problems to resolve. This is clearly not a best practice
By the way, a second technique recommended in that same W3C example suggested using nosize. As James Edwards from Brothercake reminded me in the comments, the nosize technique also fails in one of the current leading screen readers, Window Eyes 5.0. So, it too is Not a best practice.
Label hiding technique #2
The second quiz looked at another technique suggested in some rather old email correspondence about that same article. An alternative proposal was to not use the form label at all, but to add a title attribute to the form control. OK, sigh, we tested that idea too. The results were a bit more consistent. Screen readers will generally use the title text if it is available, especially in forms reading mode. My complaint with this technique is that it completely bypasses using the correct structural element, the label. In short, it is not compliant with yet another WCAG guideline (4.1) which advises using technology correctly. Not a best practice.
Multiple labels
Then, along comes Patrick Lauke who wonders about how well multiple labels work. I asked “Why have multiple labels?” Owen Rodda proposed using multiple labels for handling errors during forms validation. Use the first label as the regular label for the field, and a second as an error notification, if needed. Once again, we find surprises. A couple of the screen readers merrily speak all the labels we might want to assign to a field. Jaws, however is inconsistent (again). Of three different reading modes tested, two modes speak only the last label of a set of four. In the other reading mode, Jaws speaks the first label of a set of four. Two thirds of the time Jaws might speak what you want, but three thirds of the time it’s wrong if you wanted multiple labels spoken! If you are going to use this technique, constrain yourself to no more than two labels. That will get you to probability 0.66 with Jaws.
Legend and fieldset
OK. Let’s move along. This next one should be very straightforward and simple. We have a tool for grouping like items together, fieldset. We can then use legend within fieldset to provide information about the group of fields contained within the fieldset. Looking back on the first test case for this series, we had a simple text paragraph and two controls. The better implementation of that example uses a fieldset to wrap around the two controls, a legend to replace that text paragraph, and proper labels to keep the controls from being ambiguous. Take a look at the new fieldset and legend test case to see the difference. Try it in screen readers if you please. Even without testing it extensively, I expect it to behave very well in screen readers, and exactly as we expect. Styling? That’s a different question, with an answer coming up next.
Best practices
The best practices are simple. Use the structural elements we’ve been given. Legends and labels are structural elements; highly recommended. Title attributes are very poor substitutes. The only reason to use them is as redundant information in the hopes that older screen readers will speak them. However, don’t depend on titles alone. Group like items together with a fieldset and then use the fieldset’s legend to add supplemental instruction for that group of controls. Use real labels on every control to insure their meaning is obvious. Just because the legend says, “update month and year,” we shouldn’t assume the first control is actually the month. Label it! Avoid hiding labels. Any innovative designer should be able to create a form that uses legends and labels with no need to hide either, and the W3C should ditch their example of hiding labels.
If there is no other choice than to hide labels, use the techniques we know work universally well: offtop and offleft. Do not use display:none; It is unreliable and inconsistently implemented in screen readers. Do not use nosize as it fails in the latest version of a popular screen reader. You can also check other techniques that we have previously tested.
Now, let’s add some style. Cameron Adams, the “Man in Blue” has already done a very fine article on Accessible, stylish form layout. He builds on the original article with a set of form templates which show you six different ways to layout a form. Very nice work indeed.
Lastly, try the fieldset and legend test case in screen readers and let us know what you hear. It might also be fun to point your screen readers at Cameron’s form templates.
September 10th, 2005 at 5:05 pm
Jaws 6.0 and IE6 - straight through reading mode
Everything is spoken exactly as displayed.
Listen to a recording.
September 10th, 2005 at 5:07 pm
Jaws 6.0 and IE6 - forms reading mode
Interrupted reading, pressed F to find the form, which Jaws read completely. Then tabbed to each control. For each control the legend was spoken and then the label and control contents.
Listen to a recording.
September 10th, 2005 at 5:10 pm
Window Eyes 5.0 and IE6 - straight through reading mode
Everything was read as displayed, but with the addition of the control label being repeated after speaking the current control value.
Listen to a recording.
September 10th, 2005 at 5:15 pm
Window Eyes 5.0 and IE6 - forms reading mode
Interrupted normal reading, used F to find the form which was spoken, then used C to find and speak each control.
When speaking the complete form, each control’s label is spoken twice, once before and once after the control’s current vaule. When speaking individual controls, the label is spoken only once, after the control’s current value.
Listen to a recording.
September 10th, 2005 at 5:27 pm
IBM Home Page Reader 3.04 - straight through reading mode
Information is spoken exactly as displayed.
Listen to a recording.
September 10th, 2005 at 5:30 pm
IBM Home Page Reader 3.04 - form reading mode
Interrupted reading and used Alt+o to move to controls. The legend was spoken once at the start of the form. Each of the other controls spoke the control’s label and value. Each label is spelled out letter by letter due to a known bug.
Listen to a recording.
September 11th, 2005 at 4:42 am
How come you’re recommending “nosize” as a universally suitable technique, when we know that it fails for some - http://www.access-matters.com/2005/04/24/quiz-527-screen-reader-test-7/
offleft and offtop positioning, fab, but nosize is just as broken as display:none for practical use.
September 11th, 2005 at 6:35 am
THANKS James! (Brothercake) You are correct. I overlooked the Window Eyes 5.0 failures for nosize. That one has enough market share to recommend against using this technique. I’ll revise the recommendation.
Thanks for catching it.
September 11th, 2005 at 9:38 am
Have you tried using this technique?
label {
font-size: 0;
margin-left: -9999px;
text-indent: -9999px;
}
select {
display: block;
float: left;
}
September 11th, 2005 at 2:08 pm
Tobias,
Refer to all the testing done previously. You can see that what you propose is a combination of techniques #7 (nosize), #9 (offleft) and #11 (negative text indent). Using all three is unnecessary overkill. Use only #8 or #11, and let the browser do less work.
July 5th, 2006 at 5:26 pm
[…] Speaking form labels - summary […]
June 24th, 2008 at 6:33 am
I am facing sm issues .
1) How to make JAWS read iframes..in my website i have used iframe for popup’s. so wen a popup comes jaws doest read out which popup comes. i tried by giving a title attribute to the iframe but it doesnt seem to help.
However it reads out for every popup wen im using firefox. i want same thing even in IE.
2) How to make JAWS read LABELS. only label.
i have a label inside a