Scope

In the simple table shown in Figure 13-9, it is easy to tell that the headers apply to their respective columns of data. In more complex tables, the relationships between headers and data may not be so straightforward. The scope attribute in the th element is used to explicitly declare associations between table headers and the rows, columns, row groups, or column groups in which they appear (using the values row, column, rowgroup, and colgroup, respectively)

The table example in Figure 13-10 has been altered slightly to include table headers for each row.

Table with row and column headers

Figure 13-10. Table with row and column headers

In this case, it is desirable to make it clear that the headers in the left column apply to each data cell in the rows in which they appear. It is helpful to indicate the relationship of the cells with their respective column header as well. This revised markup shows how the scope attribute is used to indicate these relationships.

    <table summary="A comparison of major features for each planet in the solar system,
 relative to characteristics of the Earth.">
    <caption>Solar System Summary</caption>
      <tr>
        <td></td><th scope="col"abbr="diameter">Diameter measured in earths</th>
        <th scope="col"
abbr="orbit">Orbital period in years</th>
        <th scope="col">Moons</th>
      </tr>
      <tr>
        <th scope="row">Mercury</th>
        <td>.38</td>
        <td>.24</td>
        <td>0</td>
      </tr>

      <tr>
        <th scope="row">Venus</th> <td>.95</td> ...

Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.