HTML <caption> tag

Updated: 10/11/2017 by Computer Hope

HTML caption tagWhen writing in HTML, the <caption> tag is a block element used to add a title to a table. It should be noted that if you are using the <caption> tag inside of a <table> tag that is the only element in a <figure>, use <figcaption> instead. The following sections contain information about the <caption> tag, including an example of it in use, as well as related attributes and browser compatibility.

Example code

<table class="mtable2 tab">
<caption>I'm a Table Caption</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr class="tcw">
<td>March</td>
<td>$200</td>
</tr>
<tr class="tcw">
<td>April</td>
<td>$300</td>
</tr> <tr class="tcw">
<td>May</td>
<td>$250</td>
</tr>
</table>

Example result

I'm a Table Caption
Month Savings
March $200
April $300
May $250

As you can see in the previous example, there is a title just above the table; it was put there using the <caption> tag. We have also used CSS to added classes to the table and its rows to make them look nicer.

Deprecated attributes

Within an HTML tag, an attribute dictates certain aspects of an HTML element. Attributes are made up of a name and value pair; all tags support standard attributes. The <caption> tag only has one unique attribute that became deprecated and the obsolete within HTML5. The following table shows that attribute, as well as a description of what it did.

Attribute Description
align Designated the alignment of the table caption

Compatibility

Internet Explorer Firefox Safari Opera Chrome
All versions All versions All version All versions All versions

Browser, Compatibility, Parent and child, Title, Web design terms