Open In App

How to define a table caption using HTML ?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we define a table caption by using the <caption> tag element. The caption element 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>

Example:




<!DOCTYPE html>
<html>
  
<head>
    <style>
        table,
        th,
        td {
            border: 1px solid black;
        }
  
        #GFG {
            font-size: 25px;
            color: green;
        }
    </style>
</head>
  
<body>
    <h1 style="color:green;font-size:35px;">
        GeeksForGeeks
    </h1>
  
    <h2>
        HTML5: How to define 
        a table caption?
    </h2>
  
    <table>
          
        <!-- Adding caption to the table -->
        <caption id="GFG">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 are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


Last Updated : 20 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads