HTML <caption> Tag

<caption> tag is used to give a title for a table.

We must put <caption> tag just after <table> tag.

The <caption> tag comes in pairs.

We must write the content between the opening (<caption>) and closing (</caption>) tags.

As looking, it will be placed at the top of the table.

Check the code below:

<table summary="grades" width="400" border="1">
   <caption>Mathematic Grades</caption>
   <thead>
      <tr>
         <th>Student</th>
         <th>1st Exam</th>
         <th>2nd Exam</th>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td>Tigran Aleksanyan</td>
         <td>75</td>
         <td>65</td>
      </tr>
      <tr>
         <td>Armine Kocharyan</td>
         <td>55</td>
         <td>80</td>
      </tr>
      <tr>
         <td>Hasmik Sargsyan</td>
         <td>60</td>
         <td>47</td>
      </tr>
   </tbody>
</table>

Check how it looks as a result:

As you can see; "Mathematic Grades" is a title which is written via <caption> tag and it is placed at the top of the table.

Attributes:

This tag use the Global Attributes and there is one attribute below which is not supported anymore by HTML5.

Attributes Values Description
align right
left
center
It was used to align the content inside cells.
This attibute is not supported by HTML5