A matter of semantics. If I have a HTML page that is basically one big table, what element do I use for a header?
Ordinarily, you'd use a h1 for the heading of the page, and a caption for the table's heading. But what if the table is the only thing on the page? Including both looks a bit silly. So do I use a h1 and forget about the caption, or vice versa?
Are there formal (W3C or WHATWG) recommendations about this? If so, I can't find them.
PS For the sake of this question, let's assume that the table is filled with tabular data, OK.
A table caption can contain free-form content. You could include a description of the table within the caption element, leaving the title for a heading element, and it wouldn't look silly at all.
The spec for the caption element contains an example:
In the abstract, this table is not clear. However, with a caption giving the table's number (for reference in the main prose) and explaining its use, it makes more sense:
<caption> <p>Table 1. <p>This table shows the total score obtained from rolling two six-sided dice. The first row represents the value of the first die, the first column the value of the second die. The total is given in the cell that corresponds to the values of the two dice. </caption>
If the table is self-explanatory, you can leave out the caption, but I still recommend having a document-level heading. Headings are a crucial part of the document outline while caption does not play a role (and, notably, neither does the title element, even though it represents the document title). Even though no real-world implementations of the outline exist anyway, you can't go wrong with having a document-level heading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With