CSS in Action: Invisible Content Just for Screen Reader Users
Article Contents
Introduction
Most of the techniques for making web content accessible to screen readers
are invisible to visual users. Alternative (alt)
text, table header tags, table summaries, and form <label>
tags are examples of techniques that make a big difference for screen reader
users, but which have little or no impact on the visual appearance of the
web content.
Every once in a while, though, web designers confront situations in which the addition of accessible markup does have an impact on the visual layout. In some cases, this visual impact can decrease the usability of the content for visual users. In other cases, designers simply want to provide a more pleasing layout or appearance that would be compromised by including all of the text in a semantically correct format.
Hiding Text from Sighted Users
Fortunately, there are ways of resolving the conflicts between the needs and desires of visual users and those of screen reader users. This paper examines a few circumstances in which hiding text from visual users can be beneficial, and proposes a solution which allows HTML to be hidden without compromising the accessibility or semantic integrity of the document, and which works across browsers and platforms.
The essence of the technique proposed in this document is to hide the content above the viewable area of the browser and to also shrink the content to a height and width of 1 pixel. The combination of moving the content and shrinking it is what allows this technique to work across a wide range of browsers and platforms.
Sample Code 1
The following code should appear in the style sheet:
.hidden
{position:absolute;
left:0px;
top:-500px;
width:1px;
height:1px;
overflow:hidden;}The CSS class should then be referenced from within the tag of the element being hidden, as shown:
<div class="hidden">This text is hidden.</div>
Sighted users will not see the hidden content at all. It will be out of their viewing range, hidden above the top of the browser window. Screen reader users will have access to the content as if it were not hidden at all. Screen readers read the content normally, completely ignoring the styles used in this technique.
Some browsers respond well to the first half of this technique, which is to place the element above the browser’s viewport. Other browsers do not respond to this method, so the second technique, of making the element too small to see is also used. Both methods are necessary to account for the variations in browser implementation. The distance of 500 pixels above the viewport is a randomly selected number. Any distance will suffice, as long as it places the content out of the viewing range of sighted users. Placing the content above the viewport is preferable to placing it to the left or right of the viewport because both of these other directions cause display irregularities in some browsers. The height and width of the element are set to 1 pixel, as opposed to 0 pixels, because some screen readers refuse to read content that is has no width or height. Setting the overflow to "hidden" takes other browser implementation bugs into account. Together, these methods work across a broad range of browsers, platforms, and screen readers.
Graphics used as headers
Designers have always sought to make web content as visually pleasing
as possible. The markup language of HTML
produces rather bland-looking content without the addition of graphics
or other media elements. A favorite technique of visual designers is to
use graphics as document headings. This technique allows designers to
have more control over the look and feel of the headings than simple text
does. Unfortunately, this produces documents that do not provide good
semantic structure on the level of the markup. Screen readers cannot recognize
these elements as headings without the proper markup (i.e. <h1>,
<h2>, etc.). Surrounding a graphic with
heading tags does not quite solve the problem either. In a semantic sense,
headings should be text.
Several techniques have been presented to allow developers to use graphics as headers within semantically-correct documents. The first, and most widely-known technique is Todd Fahrner’s image replacement technique [1]. Soon after its introduction, accessibility experts noticed that the technique made the content unavailable to screen readers [2]. Not long thereafter, several people introduced alternative techniques, such as Bob Easton’s off-to-left-technique [3], Mike Rundle’s text-indent method [4], and others. All of these techniques succeed in hiding HTML content, some of them succeed in making the content accessible to screen readers, and some of them work across all major browsers and operating systems. However, none of them succeed in all three of these areas, though some are better than others.
Sample Code 2
The following code should appear in the style sheet:
.hidden
{
position:absolute;
left:0px;
top:-500px;
width:1px;
height:1px;
overflow:hidden;
}
h1
{
height:30;
width:60;
background-image:url(h1.jpg);
}
The CSS class should then be referenced from within the tag of the element being hidden, as shown:
<h1><img src="h1.jpg" alt="" height="30" width="60"><span class="hidden">This heading text is hidden.</span></h1>Forms within data tables
To a visual user, table header cells can perform the dual function of organizing table content and also providing labels for the form elements within that table, as seen in the screenshot of a form within a data table below.

Figure 1. Data table used to provide "labels" for form elements
To a screen reader user, the table row and column headers are somewhat useful
in terms of understanding the layout of the table, but the headers do not act
as form labels. When screen reader users tab from one form element to another,
they will not hear the table headers read to them. In fact, they will not hear
any label at all. Screen readers require text labels. Ideally, these labels
should be wrapped in the <label> tag, as recommended by WCAG 1.0. Additional
labeling and grouping can be accomplished by using the <fieldset> and <legend> tags.
In this particular instance, however, visual users will not receive any added
benefit from the visual text labels. To them, such text labels would be redundant
with the table headers, since, in a visual sense, these headers already provide
adequate labels for the form elements. Here is how the same table would look
to visual users if standard text labels were added, with the <label> tag, <fieldset> tag,
and <legend> tag:

Figure 2. Form with labels within a data table.
Though screen reader users will be happy with this version of the table, most sighted users will find the additional text to be a distraction. To visual users, the table has just become more crowded, wordy, and harder to understand at a glance. This is a situation in which the addition of markup intended to benefit screen reader users interferes with the accessibility, or at least the user-friendliness of the content to visual users.
Sample Code 4
The following code should appear in the style sheet:
.hidden
{
position:absolute;
left:0px;
top:-500px;
width:1px;
height:1px;
overflow:hidden;
}
The CSS class should then be referenced from within the tag of the element being hidden, as shown:
…
<label for="amembers" class="hidden">Number of members in team A</label>
…
Multiple form elements that "share" a single label
Another example of apparent incompatibility between the needs of screen readers users and visual users occurs when developers create multiple form elements that seem as though they ought to belong to the same label. A common example of this is when two, or more text input elements are used for phone numbers.
Figure 3. Form labels that apply to more than one form element.
In the screenshot above, most visual users in North America will understand that the individual text input areas correspond to the different sections of standard phone numbers. Screen reader users may attempt to enter the entire phone number in the first box. When they discover that the box limits them to only 3 characters, this will likely lead to some confusion. Some users will be able to figure out the entire context after experimenting with it, but this kind of experimentation takes time, and is unnecessary.
The most obvious workaround for this particular problem would be to combine all of the text input boxes into a single text input box, and then provide the appropriate label. This may be the best solution in most circumstances in almost every way. Nevertheless, the CSS technique can be applied to this situation also.
Sample Code 5
.hidden
{
position:absolute;
left:0px;
top:-500px;
width:1px;
height:1px;
overflow:hidden;
}
The CSS class should then be referenced from within the tag of the element being hidden, as shown:
<form method="post" action="">
<p>Phone number:
(
<label for="area" class="hidden">Area code</label>
<input name="area" type="text" size="3" maxlength="3" id="area" />
)
<label for="first" class="hidden">first 3 digits</label>
<input name="first" type="text" size="3" maxlength="3" id="first" />
-
<label for="last" class="hidden">last 4 digits</label>
<input name="last" type="text" size="4" maxlength="4" id="last" />
<label for="ext" class="hidden">extension</label>
<input name="ext" type="text" size="5" maxlength="5" id="ext" />
</p>
<p><input type="submit" name="Submit" value="Submit" /></p>
</form>
Providing contextual cues just for screen reader users
The same CSS technique can be used to provide contextual cues especially for screen reader users that visual users would not need to see. As long as this technique is not over-used, screen reader users can benefit from text messages that explain the context of the web content to them. For example, sites with complex menu systems are often designed with graphical interfaces that organize the menu hierarchies into visual spaces. Visual "tabs" are frequently used for this purpose. Oftentimes, the menu system is designed so that it highlights the user's position within the menu hierarchy. Most of this information is lost on screen reader users because it is all conveyed visually. It may be appropriate to provide hidden phrases that allow screen reader users to orient themselves within such structures. Phrases that may be useful and appropriate to insert within the content include:
- Begin main menu.
- End main menu.
- Begin [and End] the Products and Services submenu
- You are here [followed by the text of the current menu item within the hierarchy]
- Advertisement [place this before a banner ad, for example]
A word of caution: all of these phrases should be brief, and should be used sparingly, if at all. Many sites do not need to resort to this kind of contextual help. The simpler and cleaner the design, the less of a need there is for this technique. Designers should not overburden screen reader users with text that provides little or no benefit to them. This technique can provide important contextual cues that are otherwise only visual in nature, but since screen reader users have to listen to whatever text is in the page, these cues should be kept to a minimum.
Sample Code 6
The following code should appear in the style sheet:
.hidden
{
position:absolute;
left:0px;
top:-500px;
width:1px;
height:1px;
overflow:hidden;
}
The CSS class should then be referenced from the <label> tag, as shown:
<div class="hidden">Begin main menu.</div>
...
<div class="hidden">End main menu.</div>Conclusion
When the CSS technique presented here is used to hide form HTML content, sighted users will never know that the content is there at all. Screen reader users, on the other hand, will never realize that this content is invisible to sighted users. Both kinds of users will be able to use the content intuitively, without having to adjust for either too much or too little information in the markup. This can provide important contextual cues that are otherwise impossible for screen reader users to grasp because of the visual nature of these cues. When used judiciously, this technique can ameliorate some of the tension between the demands of accessibility and the demands of visual design. It is not the only technique or method of solving this problem, but it is one that web developers can add to their list of possible solutions when the need arises.
See Also:
- Using background-image to replace text - external link
- Facts and opinion about Faherner image replacement - external link
- Screen reader visibility - external link
- Accessible image replacement - external link
- U.S. Access Board (2001). Summary of Section 508 Standards - external link
- W3C (1999). Web Content Accessibility Guidelines 1.0 - external link