<caption> Tag HTML <caption> Element
The <caption> tag in HTML is used to specify a caption or title for a <table> element. The caption appears centered above the table and helps to provide context or a brief description of the table's content.
Here is an example of how to use the <caption> tag:
<table>
<caption>Monthly Sales Data</caption>
<tr>
<th>Month</th>
<th>Sales</th>
</tr>
<tr>
<td>January</td>
<td>5000</td>
</tr>
<tr>
<td>February</td>
<td>6000</td>
</tr>
</table>
In this example, the caption Monthly Sales Data appears above the table, providing information about the content of the table.
Main <caption> Tag Attributes
| Attribute | Description |
|---|---|
| align | Specifies the alignment of the caption text. Possible values include top, bottom, or left. |
| valign | Specifies the vertical alignment of the caption text. Possible values include top, bottom, or middle. |
Here is an example of using the align attribute:
<table>
<caption align="top">Monthly Sales Data</caption>
...
</table>
And here is an example of using the valign attribute:
<table>
<caption valign="bottom">Monthly Sales Data</caption>
...
</table>
Experiment with these attributes to see how they affect the appearance of the caption in your tables.