HTML <caption> tag

Use of <caption> tag

The <caption> tag is used to add caption or title to an HTML Table.
By default, the <caption> will be align in center. It must add just after the <table> tag (on-tag). You can add only one caption per table.
Type: Block Element

Example of <caption> tag

<caption> Name of the table </caption>

Supported Browsers

Tag Chrome browser Internet explorer browser Firefox browser Safari browser Opera browser
<caption> Yes Yes Yes Yes Yes

Full Code Examples

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table style="width:100%">
<caption> 3 rows and 3 columns table </caption>
<tr>
<th> Name </th>
<th> Age </th>
<th> Standard </th>
</tr>
<tr>
<td> Tom </td>
<td> 9 </td>
<td> 7 </td>
</tr>
<tr>
<td> Bruise </td>
<td> 10 </td>
<td> 7</td>
</tr>
</table>
</body>
</html>

Output

3 rows and 3 columns table
Name Age Standard
Tom 9 7
Bruise 10 7

Attributes of <caption> tag

Attribute Value Notes
align top
right
bottom
left
It defines the alignment of the caption.

Note that: align attribute is not supported in HTML5. Use CSS instead.

More Reference

Default CSS properties of caption tag:

caption {
display: table-caption;
text-align: center;
}