HTML <caption> Tag

The <caption> tag is used to define the header of the table. The tag itself must be inside the <table> element immediately after the opening (<table>) tag.

Syntax

The <caption> tag comes in pairs, which means that the content is written between the opening (<caption>) and the closing (</caption>) tags.

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <table  width="400" border="1">
      <caption>Evaluation paper</caption>
      <thead>
        <tr>
          <th>Student</th>
          <th>1st exam</th>
          <th>2nd exam</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>John Johnson</td>
          <td>75</td>
          <td>65</td>
        </tr>
        <tr>
          <td>Mary Nicolson</td>
          <td>55</td>
          <td>80</td>
        </tr>
        <tr>
          <td>Max Thomson</td>
          <td>60</td>
          <td>47</td>
        </tr>
      </tbody>
    </table>
  </body>
</html>

Result

Evaluation paper
Student 1st exam 2nd exam
John Johnson 75 65
Mary Nicolson 55 80
Max Thomson 60 47

Attributes

Attribute Value Description
align Aligns the header horizontally.
Not used in HTML5.
right the header is placed on top and aligned to the right.
left the header is placed on top and aligned to the left.
top the header is placed on top and aligned to the center.
bottom the header is placed below and aligned to the center.

The <caption> tag supports the Global Attributes and the Event Attributes.

Browser support