The caption tag in HTML provides a caption or title for an HTML table. It should be placed immediately after the table tag and contain the caption text. In this tutorial, you will learn about HTML <caption> Tag.
What Is HTML <caption>
Tag?
The caption tag is typically displayed above the table in bold font to distinguish it from the rest of the content. It helps provide a brief description or summary of the information contained in the table or for giving the table a title that identifies its purpose or contents.
Here is an example of how the caption tag can be used on an HTML page:
Example:
<table>
<caption>Company Sales Data</caption>
<tr>
<th>Year</th>
<th>Sales</th>
</tr>
<tr>
<td>2021</td>
<td>$200,000</td>
</tr>
<tr>
<td>2022</td>
<td>$210,000</td>
</tr>
</table>
In this example, the caption tag contains the text "Company Sales Data," which will be displayed as the table's title. The title is usually displayed above the table in bold font to differentiate it from the rest of the content.
It is worth noting that the caption tag is optional, and a table may not have a caption if it is not required.