There are two basic uses for tables on the web: data tables and layout tables. While accessibility guidelines do not prohibit using tables for layout, CSS-based layouts are recommended in order to retain the defined semantic meaning of the HTML. If you must use a table for layout, ensure your content makes sense in linear order of the source and use <table role=”presentation”> to hide the table element from assistive technology such a screen readers.
Data tables are used to organize data with a logical relationship in grids. Accessible data tables need HTML markup that indicates header cells and data cells, and defines their relationship. Assistive technologies use this information to provide context to users.
To make simple tables accessible, header cells must be marked up with <th>, and data cells with <td>. For more complex tables, explicit associations may be needed using scope, id, and headers attributes.
This tutorial shows you how to apply appropriate structural markup to tables. It includes the following pages:
- Tables with one header for rows or columns: For tables with content that is easy to distinguish, mark up header cells with <th> and data cells with <td> elements.
- Tables with two headers have a simple row header and a simple column header: For tables with unclear header directions, define the direction of each header by setting the scope attribute to col or row.
- Tables with irregular headers have header cells that span multiple columns and/or rows: For these tables, define column and row groups and set the range of the header cells using the colgroup and rowgroup values of the scope attribute.
- Tables with multi-level headers have multiple header cells associated per data cell: For tables that are so complex that header cells can’t be associated in a strictly horizontal or vertical way, use id and headers attributes to explicitly associate header and data cells.
- Caption & Summary: A caption identifies the overall topic of a table and is useful in most situations. A summary provides orientation or navigation hints in complex tables.
Some document formats other than HTML, such as PDF and Word, provide similar mechanisms to markup table structures. Be careful, as table markup is often lost when converting from one format to another, though some programs may provide functionality to assist converting table markup.
Why is this important?
Tables without structural markup to differentiate and properly link header and data cells create accessibility barriers. Relying on visual cues alone is not sufficient to create an accessible table. With structural markup, headers and data cells can be programmatically determined by software, which means that:
- People using screen readers can have the row and column headers read aloud as they navigate through the table. Screen readers speak one cell at a time and reference the associated header cells, so the reader doesn’t lose context.
- Some people use alternative ways to render the data, for example by using custom stylesheets to display header cells more prominently. Techniques like this enable them to change text size and colors, and display the information as lists rather than grids. In order to allow alternative renderings, table code needs to be properly structured.
Source: W3C/WAI – Tables Concepts
Accessify.com’s quick table builder creates accessible tables using a wizard as a guide.