Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to add a title to a table?

Tags:

html

semantics

Which element should I use for titles of tables, <caption> or <th>?

For example, I want to create this table :

enter image description here

What is better,

<tr><th colspan="2">Discographie</th></tr>

or

<caption style="font-weight: bold">Discographie</caption>

?

like image 709
user3790069 Avatar asked Jul 19 '14 08:07

user3790069


1 Answers

th corresponds to the title of the column, so in that case : "Album" and "Année"

W3C : "The th element represents a header cell in a table." https://www.w3.org/WAI/tutorials/tables/one-header/

caption corresponds to the title / description of the whole table, so yes, you'd better use caption for "Discographie".

W3C : "The caption element represents the title of the table that is its parent." https://www.w3.org/WAI/tutorials/tables/caption-summary/

Plus, it is easier to maintain as your table grows

like image 168
Clément Malet Avatar answered Oct 23 '22 12:10

Clément Malet