HTML Caption Tag <caption> is used to provide a caption to a table in HTML 5. The HTML Caption Tag must be places just after the HTML Table Tag.
Only one Caption is allowed per table in an HTML webpage. The caption of a table is aligned as center by default by HTML Caption Tag.
Caption Tag align attribute is removed in HTML 5 and is deprecated in HTML 4.01. Caption tag is a closed tag and needs closing Caption Tag </caption>
HTML Caption Tag Syntax
<table> <caption> Table Caption Goes Here </caption> Table rows and data goes here.. </table>
HTML Caption Tag Attributes
HTML Caption Tag Attribute | Value | Description |
align | left, right, top, bottom | Specifies the alignment of the caption of table in HTML. Not Supported in HTML 5. |
HTML Caption Tag supports all HTML Global Attributes and HTML Event Attributes.
HTML Caption Tag Example
HTML Caption Tag Code | Output | ||||||||
</pre> <table border="1"><caption>Top 3 Ranks are</caption> <tbody> <tr> <th>Rank</th> <th>Name</th> </tr> <tr> <td>John</td> <td>1</td> </tr> <tr> <td>Jack</td> <td>2</td> </tr> <tr> <td>Jill</td> <td>3</td> </tr> </tbody> </table> <pre> |
|
The above HTML Caption Tag example shows that by default the caption of the table is aligned at center of table.
HTML Caption Tag Supporting Browser
S. No. | Browser | Supported(Yes/No) |
1 | Internet Explorer | Yes |
2 | Firefox | Yes |
3 | Google Chrome | Yes |
4 | Opera | Yes |
5 | Safari | Yes |