Table of contents
Bypass table of contentsTwo types of cells can be defined in an HTML table. One of them is the simple cell (HTML td element), already defined in the "simple table" example, and the other one is a special type of cell (HTML th element) that contains header information for a set of specified cells.
Browsers may render the content of header cells in a special way (usually as centered bold text), attributes that can be visually achieved by using a normal cell (HTML td element) with presentational attributes (centered bold text). But header cells provide more information that may be helpful for non-visual browsers (spoken browsers may speak to the user the cells content while immediately associating it to the header cell) and spiders (like search engines spiders).
The cells affected by a header cell can be defined in different ways, but the most common and simple is to use the scope attribute. Set in both, the HTML td tag and the HTML th tag, this attribute can take four values: "row" and "col" affecting the containing row or column respectively, and "rowgroup" and "colgroup" affecting the containing group of rows or columns (described further in this tutorial).
In the example below the same "simple table" is defined but this time with header cells using the "scope" attribute:
| Column 1 | Column 2 | Column 3 |
|---|---|---|
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |
As we can deduct from the previous paragraph, in this example, the column 1 gives header information for the cells 1 and 4, the column 2 for the cells 2 and 5 and the column 3 for the cells 3 and 6.
Note that, as this attribute can also be defined in normal cells (HTML td tag), normal cells can act as header cells too. This is the case when a cell provides both, header information and data. In any other case header cells should be used (HTML th tag).
Another way to associate header cells to normal cells is using the attribute "headers". This attribute is defined in a normal cell (HTML td tag) and refers to a set of cells (using their "id" attributes, separated by spaces) that provide header information for it.
There is a low (and very rare) number of cases where this attribute can't be replaced with the "scope" attribute. The next example shows an overlaid table, where there's an oblique line of cells that goes from the top left corner to the bottom right corner and serves as limit to define which cells receive the top and right headers and which the left and bottom.
| H1 | H2 | H3 | ||
|---|---|---|---|---|
| H4 | C1 | T1 | T2 | H7 |
| H5 | B1 | C2 | T3 | H8 |
| H6 | B2 | B3 | C3 | H9 |
| H10 | H11 | H12 |
The information in this table isn't fully visual, but semantically it provides a wel defined set of headers for each cell. For example, the cell "C1" (in the oblique axis) with four headings (H1, H4, H7 and H10), and the cell T1 (on top of the axis) with two (H2 and H7).
This type of table is one of the few uses where "scope" (the simple way) wouldn't work, and is mostly used for showing scientific data.
This attribute can be defined for header cells as well as for normal cells, and group headers and data by categories, in which the cells can be clasified. Although its use is a little complex, it gives new and expanded ways to provide header information, specially in the case of spoken browsers for blind people.
The following example illustrates the use of "axis" as a way to make the data more readable and understandable.
| Country | Automobiles | Autoparts | Supplies | Balance |
|---|---|---|---|---|
| United States | $5.432.551 | $3.275.268 | -$2.235,528 | $6,472,291 |
| United Kingdom | $3,763,221 | $1,342,231 | -$982,268 | $4,123,184 |
| France | $2.458.197 | $2.456.841 | -$1.315,548 | $3,599,490 |
| Canada | $1.846.548 | $448.556 | -$351,559 | $1,943,545 |
This example sets two type of axes or categories: a region category (Europe and America) and an income/outcome category. In a spoken web browser this non-visual information makes a lot of sense and helps undestanding the difficult table sctructure a lot better.
Diseño y desarrollo: Latitud29.com