HTML and CSS

Adding a Caption

You can caption your table using the caption element.

<caption>. . . </caption>

Place your caption content between the opening and closing tag of the caption element. The caption goes directly beneath the opening table tag and is displayed by most browsers centered above the table (see Example 4-7).

Example 4-7. Adding a caption to the table
<table width="90%" border="1" cellspacing="5" cellpadding="5">
<caption>Comparing weather and time zones</caption>
<tr>
<th>Location</th>
<th>Tucson, Arizona</th>
<th>Las Vegas, Nevada</th>
</tr>
<tr>
<th>Weather</th>
<td>Warm to Hot</td>
<td>Warm to Hot</td>
</tr>
<tr>
<th>Time Zone</th>
<td>No Daylight Savings</td>
<td>Mountain Standard Time</td>
</tr>
</table>

Figure 4-9 shows the results.

Figure 4-9. Adding a caption.