Skip to: content, navigation

by Ian Lloyd

headers (HTML attribute)

Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Full Full Full Full
Spec
Depr. Version
No HTML 4
headers="cell ID …"

Example

The following example shows how headers associates the header cells with the body cell contents:

<table border="1">
  <tr>
    <th colspan="4" id="hdr_work">Work Contact Points</th>
  </tr>
  <tr>
    <th id="hdr_n">Name</th>
    <th id="hdr_e">Email</th>
    <th id="hdr_p">Phone</th>
    <th id="hdr_f">Floor/Block</th>
  </tr>
  <tr>
    <td headers="hdr_work hdr_n">Fred</td>
    <td headers="hdr_work hdr_e">fred@megacorp.com</td>
    <td headers="hdr_work hdr_p">123456</td>
    <td headers="hdr_work hdr_f">1/A</td>
  </tr>
</table>

Description

This attribute is another one that exists for the purposes of improving the accessibility and understanding of the data table for users who can’t see the data—typically users with screen reading software. The headers attribute could be translated by the web browser as, "to understand what the data in this cell right here means, you need to be looking at that table header location over there and that other one over there." A user who views the cell in question can very quickly scan up the table from that point to view the table headers above and to the left of it, to get an understanding of what’s going on. The headers attribute provides explicit instructions to the browser as to which table headers are relevant, by referencing the id attributes for the header cells in question.

Look at the example HTML above. Fred’s email address is in this row:

<td headers="hdr_work hdr_e">fred@megacorp.com</td> 

The headers attribute contains two values: "hdr_work" and "hdr_e". If you look at the top of the table markup, you’ll notice that those values are contained in the id attributes for the respective cells:

<th colspan="4" id="hdr_work">Work Contact Points</th>

Here’s the other one:

<th id="hdr_e">Email</th>

So, with the correct keyboard combinations, a screen reader user could ascertain that the data is an email address (although that’s not too difficult to guess, even without the extra markup!), and that it’s a work contact point.

Note that in the example above, the result of the headers and id approach could also be achieved more simply using the scope attribute (even without the accessibility attributes applied, this table is simple enough that a screen reader user might be able to glean the necessary “orientation” information).

For more complex tables—those using colspan and rowspan attributes—the scope attribute will not suffice. You will need to use headers and id attributes to ensure that the table is usable for those operating assistive technology.

Value

This attribute takes a space-separated list of ids, which must match exactly (they’re case-sensitive) with the id attributes for the cells to which they relate.

Compatibility

IE5.5Full
6.0Full
7.0Full
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full

It’s difficult to state the browser compatibility for this attribute, as the issue depends on how well the assistive technology copes with this information. Regardless, the use of headers is the correct thing to do, so if you have complex tables, make an effort to ensure that you mark them up in a way that ensures that the data is accessible for all.

User-contributed notes

There are no comments yet.

Add a note

To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

Related Products

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters