Producing web pages
* HTML CSS DHTML XHTML A to Z of tags        Accessibility          Design

Spanning rows and columns

You can merge cells in tables so that they span more than one column or row. You use the colspan and rowspan attributes in the <td> and <th> tags: the colspan attribute creates a cell that spans more than one column and the rowspan attribute creates a cell that spans more than one rows.

You might, for example, span several columns with a heading.

<table width="250" border="1">
<tr>
<th colspan="2">Fruit and Vegetables</th>
</tr>
<tr valign="top" align="left">
<td>Apples</td>
<td>Celery </td>
</tr>
<tr valign="top" align="left">
<td>Oranges</td>
<td>Carrots </td>
</tr>
<tr valign="top" align="left">
<td>Bananas</td>
<td>Cabbage</td>
</table>

You might span several rows with a paragraph of text:

<table width="250" border="1">
<tr>
<th colspan="3">Fruit and Vegetables</th>
</tr>
<tr valign="top" align="left">
<td rowspan="3">Choose your favourite fruit or vegetable</td>
<td>Apples</td>
<td>Celery </td>
</tr>
<tr valign="top" align="left">
<td>Oranges</td>
<td>Carrots </td>
</tr>
<tr valign="top" align="left">
<td>Bananas</td>
<td>Cabbage</td>
</table>