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

Which element should be used for table headers, <caption>or <th>?

For example, I want to create this table:

enter image description here

What's better,

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

or

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

?

+4
source share
1 answer

th matches the column heading, so in this case: "Album" and "AnnΓ©e"

W3C: "The th element represents the header cell in the table." http://www.w3.org/TR/html-markup/th.html

caption matches the name / description of the whole table, so yes, it’s better to use the signature for "Discography".

W3C: " caption , ". http://www.w3.org/TR/html-markup/caption.html

,

+5

All Articles