Add accessibility to your AJAX applications

In December, I made a number of predictions for the 2007. I confidently predicted that Gez Lemon would discover a solution to AJAX accessibility issues. Gez had earlier defined the virtual buffer’s role in JAWS.

Understanding the virtual buffer is essential for empowering screen reader users, particularly considering the number of Web 2.0 applications that depend on Ajax. Screen readers typically take a snapshot of a web page, and place the content in a virtual buffer to allow the user to interact with the content.
Gez Lemon and Steve Faulkner –

Gez and Steve Faulkner have just released a set of javascript functions that refresh the virtual buffer by working with setAttribute. They discovered this function triggers JAWS 7.1+ screen readers to grab a new snapshot of the page.

The scripts are fairly simple. When the page loads, insert a hidden form input. When your AJAX application completes its duties, change the value of that hidden input with the setAttribute function. This setAttribute activity will refresh the buffer and the screen reader will announce the content that has been changed via an AJAX call.

The updateBuffer function presented here extends the limited improvements in JAWS 7.1 and later, by providing a mechanism to update the virtual buffer for other interface elements, that works regardless of input device. This means that users of JAWS 7.1 and later do not need to explicitly update the virtual buffer in order to interact with Ajax applications.
Gez Lemon and Steve Faulkner

As I also predicted, I believe the YUI Connection Manager will incorporate this type of functionality. This will give enhanced accessibility to thousands of web sites instantaneously.

Micropatronage for accessibility – Joe Clark style

Patronage: It ain't just for the Medicis anymore

Joe Clark has an ambitious project on the docket. The Open & Closed Project hopes to create a new standard for video captioning. It also includes plans to develop better training and certification for those creating captioning. Joe even has plans for developing and implementing new fonts that would make it easier to view the online and over-the-air captions.

However, Joe needs some help.

This project won’t run itself and needs funding. He’s asking us to help him raise the funding. Joe needs $7,777 to support 4 months of intensive fund-raising and project co-ordination. Can you help him raise this sum? If you have a friend, family member, or acquaintance that is deaf, this project will significantly help their lives.

If you go to the gym and watch the telly while sweating on a treadmill, desperately trying to figure out what the talking head is saying…. this project may or may not significantly help your life. Sometimes, you just don’t want to know what the idiot on Fox News is saying when some jerk on another treadmill is controlling the remote control… but I digress.

Visit Joe’s site and donate a few bucks. That’s all it takes. You don’t have to be a superstar to make captioning real.

Image sprites – flexible and accessible packages

User generated ratings and reviews are an important part of all Yahoo! sites. You can find them on just about every page of Yahoo! Tech.  It was important for us to develop a ratings presentation device that was easy to code, accessible, flexible, and as light-weight as possible. Our final design uses a combination of image sprites and negative text-indent to satisfy these requirements.

Product ratings are represented with 1 to 5 stars. Other sites have used inline images; repeating a solid or empty version for each of the five stars. stars image from Yahoo! ShoppingOther sites, such as Yahoo! Shopping, have used a single inline image representing the number of stars.  At best, the image will have an alt attribute that descibes the number of stars. However, the content is locked inside the image. This is an easy approach for coding but isn’t the most accessible approach.

Yahoo! Tech uses the content first approach to design

Content-first design improves accessibility. This approach places the relevant content in semantic markup. It then uses CSS to transform that content into the visual design. Here is a sample rating from Yahoo! Tech: Overall:4/5, Quality:5/5, Support: 3/5. Our CSS transform that simple text into a series of stars and accompanying text. User testing with a screen-reader user led us to remove visual descriptions from the content, i.e."stars" or "bars".

With the content in the page, it was time to look at the visual design.

Ratings are presented in either an unordered list or definition list. We need to place descriptive text in front of the stars and want the stars to be aligned with each other. These considerations lead to using spans with a combination of CSS rules to hide the text, insert a background image, and absolutely position the ratings to the right side of the list item. Let’s look at the code.

The HTML – span

To use a background image for the stars, we need a container that can be manipulated with CSS and not include presentational behaviors of its own. This is why we use the span, a generic inline container. We could use a strong or em, but feel the span offers the best versatility. You never know when the graphic designer will ask for some text to be bolded or emphasized in the same list item.

Sample code for a rating

  • Overall: 4/5

The span’s title will generate a tooltip when the user places their mouse over the rating (not Internet Explorer). Screen readers’ default settings ignore title attributes on non-form items.


Spans are inline elements.  To display background images, we need to make them display block, define a height, width, and move the text off the screen. To keep them inline with the text, we are also positioning them absolutely. We could position them relatively or floated the spans. Position absolute works the best for our pages.The parent list item is positioned relatively to give the span a contextual anchor. Negative text-indent will hide the rating text.

.ratingslist {list-style-type:none;}
.ratingslist li {position:relative; padding:3px 5px; }
.ratingslist li span {text-indent:-1000em; width:66px; display:block; position:absolute; top:5px; right:20px;}

Image sprites display the desired number of stars

The list item is given a class with a number at the end (stars8). This will display an image with four out of five red stars. We are using a scale of 0 to 10 to accomodate half stars. To display other rating variations, we change the modifier, i.e. prostars4, retstars4, bars4, bigstars4, etc…

To simplify the maintenance of the site and reduce server requests; Yahoo! Tech also uses image sprites. Sprites are single images that include multiple icons with a consistent spacing between them. Use background positioning to display the desired chunk of the image. Each sprite represents the possible color variations used on the site: red, blue, and green. Minimizing the color palettes reduces the final image size. For more information on sprites, read CSS Sprites: Image Slicing’s Kiss of Death by Dave Shea. As a further enhancement, alpha transparent png images are used for most browsers and index-transparent gifs are presented in the Internet Explorer 6 style sheets. 

Background images are positioned with the set of numbers after "no repeat." The horizontal positioning is first. Our sprite is vertical, so we are leaving it alone, hence the 0 value. The vertical positiong comes next. If we want to display 2 out of 5 stars, we need to shift the background down to that part of the image (-530px). Here is the CSS for presenting the specific star variant.

/* Ratings images
======================================= */
.stars0 span {background:url(/images/bg-ratings.png) no-repeat 0 -650px;}
.stars1 span {background:url(/images/bg-ratings.png) no-repeat 0 -620px;}
.stars2 span {background:url(/images/bg-ratings.png) no-repeat 0 -590px;}
.stars3 span {background:url(/images/bg-ratings.png) no-repeat 0 -560px;}
.stars4 span {background:url(/images/bg-ratings.png) no-repeat 0 -530px;}
.stars5 span {background:url(/images/bg-ratings.png) no-repeat 0 -500px;}
… (repeated for each variation of the stars and bars)

This approach has allowed the Yahoo! Tech engineers to maintain a consistent presentation with minimal markup. For pages that need special tweaks we can easily adjust the positioning by using descending selectors:

#mytech .ratingslist li span { right:5px;}


We’ve only found a few small issues with this approach.

  • You cannot count on background images being displayed on the printed page. Our print style sheet removes the text-indent and background images to display “Overall: 4/5”.
  • When someone includes more than 4 products in the comparison table, the text of some rating parameters will begin to overlap the stars. If they were inline images or if we floated the spans, they may drop to the next line.

Yahoo Tech! ratings are another example of creating accessible and visually dynamic pages by considering the underlying content structure before attacking the styles. Users of all abilities are presented with solid information. That’s how you can deliver a 5 star page every time.

Related Information

Captcha 2.0

Kent Brewster has come up with a novel solution for the inaccessible image-based captchas. Captchas are those images of obscured text to keep robots from spamming web sites. They’re a royal pain for those with visual disabilities.

Kent has solved this with a Web 2.0/social bookmarking bent. His RSS CAPTCHA Prototype asks you to visit a blog from his blogroll and copy the latest headline. You then paste the title into the form and if it matches, a cookie is set to say that you’re a good guy and can comment with ease in the future.

There are some inherent problems with this approach. Your visitor has to leave your page, go to another, copy the text, come back, and then paste it into your form. All of this for the sake of posting a comment. However, tabbed browsing makes this much easier. Internet savvy audiences could handle this and possibly discover some new blogs.

For WordPress users, the best approach is still the amazing Akismet spam filter. Stop the spam, not the commenter is the concept behind Akismet.

Accessibility – Voice Recognition

Robin Christopherson introduced a problem at the @media 2006 conference that I had never imagined. Can a person using voice recognition software use your image-based links? What about links that use image-replacement? It’s a simple enough question, the answer may surprise you.

Imagine your boss just messed up her shoulder jumping her Harley over 3 school buses and a hot dog cart. Worried about the lack of productivity, she purchases the latest version of Dragon Naturally Speaking or other voice recognition software. After a hard day of work, she decides to start doing some shopping online for a new television.

compare prices
The site has a big button on the product page that says: Compare Prices. Let’s make that button work for her.

Alt text to the rescue

If the link includes a simple inline image, you just need to make the alt attribute match the words in the button.

compare prices

That was pretty easy. Title attributes are ignored by the voice recognition software. Your boss will now be able to compare prices on her new television and you won’t have to worry about her complaining the next day.

Buttons that use image-replacement CSS

But what if you want a fancy button that has a hover state? It’s easy for a programmer to use CSS to replace the link text with a background image that changes on hover. If you want the link to work with voice-recognition software, you need to make sure the link text matches the button text.

I’ve had problems with this recently as the visual design changed the text on a button from "Buying Info" to "Compare Prices." Christopherson’s presentation made me realize how easy it is to break this functionality with image-replacement.

Flash – ugggh

Just hope your boss isn’t trying to shop from a site that uses Flash for their interface. She would need to use the "mousegrid" command to zero in on the link by defining the region of the screen it is located in.

Make your voice-recognition users happy

The example above is loosely based on a real-world example. My boss, Wes, injured his shoulder when he crashed his Harley on the freeway. We installed Dragon Speak on his computer to help his recovery. This is not a population you can ignore. You can insure your sites are accessible by simply matching the alt text or hidden link text to the words in the image. It’s pretty darn simple.