Skip to content

Instantly share code, notes, and snippets.

@xjamundx
Created February 6, 2012 17:51
Show Gist options
  • Save xjamundx/7793c097795a562e70c9 to your computer and use it in GitHub Desktop.
Save xjamundx/7793c097795a562e70c9 to your computer and use it in GitHub Desktop.
oDesk Accessibility Best Practices

oDesk Accessibility Best Practices

Overview

The Web Accessibility Initiative Accessible Rich Internet Applications standard is the primary standard for accessibility with HTML5. It is a W3C standard and continues to evolve along with the HTML5 spec. We should try to use this standard where appropriate as we build our website and apps. http://www.w3.org/TR/wai-aria-practices/

The principles of accessibility by definition make apps easier to use across browsers/devices. That means in addition to making the site more accessible to those with disabilities, it also improves SEO and ensures future compatibility. This document outlines a few of the low hanging fruit for accessibility that should be encouraged throughout the oDesk site.

The W3C offers a similar document here: http://www.w3.org/TR/wai-aria-practices/

HTML5 Tags

The first step to accessibility is to use the appropriate HTML5 tags. This chart from HTML5 Doctor offers some really helpful advice on when to use which sectioning tag. More details can be found in our HTML5 Best Practices documents.

Roles

Roles help screen readers know what the purpose is of certain elements or parts of the page. While using semantic HTML5 tags is a big help, IE in particular has been slow to fully make use of those new tags for helping screen readers. Because of that, we'll need to use these roles where appropriate. The full WAI-ARIA Roles page contains a more thorough explanation.

Landmark Roles

The main sections of the page should be marked up with the following roles:

  • banner (main <header>)
  • main (main <div> or <section>)
  • contentinfo (main <footer>)
  • search (any <form> specifically used for search)
  • navigation (any <nav>)
  • complementary (an <aside> used as a sidebar)

Here is an example of how that might look:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <header role="banner">
      <h1>Awesome Page</h1>
      <form role="search">
        <input type="search" placeholder="Find things...">
      </form>
    </header>
    <nav role="navigation">
      <h1>Nav</h1>
      <ul>
        <li><a href="#">Cool Stuff</a></li>
        <li><a href="#">Other Stuff</a></li>
      </ul>
    </nav>
    <div role="main">
      <h1>Main</h1>
      <p>This is the main content of the page</p>
    </div>
    <aside role="complementary">
      <h1>Sidebar</h1>
    </aside>
    <footer role="contentinfo">
      &copy; 2012 oDesk
    </footer>
  </body>
</html>

Tables

Tables are one of the trickier areas for screen readers to handle. There are a number of things we can do for accessibility to make these easier to read.

Captions / Summary

The <table> tag can have a <caption> as its first child to explain what the table is displaying. This can be used for both screen readers and browsers. Presumably a <h(n)> header right before the <table> will be similarly useful, so it's optional. <table> also has an optional summary="" attribute that can be used by screen readers only as a simple summary of the results. Please use both the <caption> element and summary attributes.

Organization

Use the semantic <thead>, <tbody> and <tfoot> tags to break your table up into its relevant sections.

Headers

Always use the <th> tag to describe headers.

Use the ARIA scope attribute to describe if the <th> element is heading up a row or a col.

In situations where there are multiple rows of headers, you should use the headers attribute to reference corresponding the id attributes of headers. More explanation of that can be found in the WCAG 2.0 docs )

<table summary="Software is pretty expensive">
  <caption>The Price of Software in US Dollars and Euros</caption>
  <thead>
  <tr>
    <th scope="col" colspan=2 id="softwareTableSoftware">Software</th>
    <th scope="col" colspan=2 id="softwareTablePrice">Price</th>
  </tr>
  <tr>
    <th scope="col" id="softwareTableSoftwareOs" >OS</th>
    <th scope="col" id="softwareTableSoftwareName" >Name</th>
    <th scope="col" id="softwareTablePriceDollar">$</th>
    <th scope="col" id="softwareTablePriceEuro">€</th>
  </tr>
  </thead>
  <tbody>
  <tr>
    <td headers="softwareTableSoftwareOs softwareTableSoftware">Windows</td>
    <td headers="softwareTableSoftwareName softwareTableSoftware">Office</td>
    <td headers="softwareTablePriceDollar softwareTablePrice" >$300</td>
    <td headers="softwareTablePriceEuro softwareTablePrice">$450</td>
  </tr>
  </tbody>
</table>

Forms

Always use a <label> to indicate what you're expecting in a form field. Feel free to also use a placeholder as this data is also made available to some screen readers. Labels require a for attribute for them to work properly, which references the id attribute of the <input>.

You should also consider using a <legend> inside each <fieldset> to articulate the purpose of the current block of fields.

Note: Consult with the HTML5 Best Practices guide for more information about how to choose id's for your form fields.

Charts and Graphs

Consider using something like jQuery Visualize to generate charts form an already accessible <table>, so that the table could be read with a screen reader and the charts made visual for this who can see it.

General Comments

  1. Consider using the x-webkit-speech attribute to make input boxes speech accessible
  2. Use the viewport meta tag to help tablet/mobile browsers know about your page (See the Mobile Web Best Practices) <meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0" />
  3. Use the alt attribute with <img> tags always. If there's no obvious alt-text, it probably should be referenced in CSS.
  4. Screen readers look inside the <a> element for an explanation of where they are going therefore <a href="#">click here!</a> is never acceptable!

Resources

  1. http://www.paciellogroup.com/blog/2012/02/rough-guide-browsers-operating-systems-and-screen-reader-support/
  2. http://dev.aol.com/dhtml_style_guide
  3. http://www.html5accessibility.com/
  4. http://www.w3.org/TR/wai-aria/
  5. http://www.paciellogroup.com/blog/2009/07/wai-aria-implementation-in-javascript-ui-libraries/
  6. http://www.w3.org/TR/wai-aria-practices/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment