HTML-Lesson 9

Tables 2

Other Table tags

The basic table tags are 'table', 'tr' and 'td'. Data cells in one or more of the top rows of a table can be enclosed in 'th' tags. This enables you to style the table headings in a different way to the remaining cells.

If you use the 'thead' tag, you should also use the 'tbody' tag to enclose the remaining rows of your table. Although the table will look right without the 'tbody' tag, it will appear as an error if you try and validate your page.

Here is such a table together with the code:

<table>
<thead>
<tr>
<th>
Column 1</th>
<th>
Column 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>
cell 1,1 </td>
<td>
cell 2,1 </td>
</tr><tr>
<td>
cell 1,2 </td>
<td>
cell 2,2 </td>
</tr><tr>
<td>
cell 1,3 </td>
<td>
cell 2,3 </td>
</tr>
</tbody>
</table>

NOTE that 'tr' tags are still used to enclose heading rows. This code results in the table:

Column 1 Column 2
cell 1,1 cell 2,1
cell 1,2 cell 2,2
cell 1,3 cell 2,3

Note that the background colour in the table heading row is done with CSS.

Previous Lesson previous lesson next lesson Next Lesson