Proper heading for a table

前端 未结 3 1324
青春惊慌失措
青春惊慌失措 2021-01-21 00:35

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 headi

3条回答
  •  终归单人心
    2021-01-21 01:23

    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:

    
    

    Table 1.

    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.

    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.

提交回复
热议问题