Skip to content
Related Articles

Related Articles

HTML <caption> Tag

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 21 Jul, 2022
View Discussion
Improve Article
Save Article

The caption tag is used to specify the caption of a table. This tag will be inserted just after the <table> tag. Only one caption can be specified for one table. It is by default aligned to the center.
 

Syntax:

<caption align = "value" ></caption>

Attributes: This tag accepts a single attribute as mentioned above and described below.

  • align: This attribute is used to specify the alignment of text content.

Below examples illustrate the <caption> tag in HTML:

Example 1: Adding a caption to the table i.e. by default aligned to the center. 

html




<!DOCTYPE html>
<html>
<body>
    <h1>GeeksForGeeks</h1>
    <h2>HTML <Caption> Tag</h2>
     
    <table>
        <!-- Adding caption to the table -->
        <caption>Students</caption>
        <tr>
            <th>Firstname</th>
            <th>Lastname</th>
            <th>Age</th>
        </tr>
        <tr>
            <td>Priya</td>
            <td>Sharma</td>
            <td>24</td>
        </tr>
        <tr>
            <td>Arun</td>
            <td>Singh</td>
            <td>32</td>
        </tr>
        <tr>
            <td>Sam</td>
            <td>Watson</td>
            <td>41</td>
        </tr>
    </table>
</body>
</html>

Output: 

Example 2: Adding a caption to the table and adding align attribute to it to align the caption to the left.

html




<!DOCTYPE html>
<html>
  <body>
    <h1>GeeksforGeeks</h1>
    <h2>HTML <Caption> Tag</h2>
 
    <table>
      <!-- Adding a caption to the table
            and aligning it to the left-->
      <caption style="text-align: left">
        Students
      </caption>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Age</th>
      </tr>
      <tr>
        <td>Priya</td>
        <td>Sharma</td>
        <td>24</td>
      </tr>
      <tr>
        <td>Arun</td>
        <td>Singh</td>
        <td>32</td>
      </tr>
      <tr>
        <td>Sam</td>
        <td>Watson</td>
        <td>41</td>
      </tr>
    </table>
  </body>
</html>

Output: 

 

Supported Browsers: 

  • Google Chrome
  • Edge 12 and above
  • Internet Explorer
  • Firefox 1 and above
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!