HTML caption Tag

HTML <caption> Tag: The HTML<caption> tag specifies the table caption. This HTML caption tag must be inserted after the <table> tag. By using the <caption> tag you can specify only one caption per table. By default, the caption is placed at the center of the table. Using CSS you can change the alignment.

HTML <caption> Tag

The HTML <caption> tag supports both the global and the event attributes. The <caption> tag must be included instantly after the <table> tag.

Syntax: <caption> Text </caption>



Browser compatibility

The HTML<caption> tag is supported by different browsers.

  • Chrome
  • Firefox,
  • Opera,
  • Safari
  • InternetExplorer

Example:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>
</head>
<body>
<table>
  <caption>Programming Languages & their Inventors</caption>
  <tr>
    <th>C</th>
    <th>Dennis Ritche</th>
  </tr>
  <tr>
    <td>Java</td>
    <td>James Gosling</td>
  </tr>
  <tr>
    <td>Python</td>
    <td>Guido van Rossum</td>
  </tr>
</table>
</body>
</html>

Output:

html caption tag

 

Attributes that are supported by the <caption> tag

Attribute Value Description
align left
right
top
bottom
Describes the alignment of the caption