HTML <caption> tag


HTML <caption> tag is used to add a caption or title of an HTML table. It should be used inside the <table> element and just after the <table> start tag. A table may contain only one <caption> element.

Syntax:

<caption>Table title...</caption>  

Following are some specifications about the <caption> tag

DisplayInline
Start tag/End tagBoth start and End tag
Usagetextual

Example 1:

<!DOCTYPE html>  
<html>  
<head>  
    <title>Caption Tag</title>  
    <style>  
        table, td, th {  
        border: 3px solid gray;  
        border-collapse: collapse;}  
    </style>  
 </head>  
 <body>  
    <h2>Example of Caption tag</h2>  
   <table width="800">  
      <caption>Employee Details</caption>  
      <thead>  
        <tr>  
            <th>Sr. No.</th>  
            <th>Name</th>  
            <th>Email</th>  
          </tr>  
        </thead>  
       <tbody>  
        <tr>  
            <td>1.</td>  
            <td>Ankit Pandey</td>  
            <td>ankit2@gmail.com</td>  
        </tr>  
        <tr>  
            <td>2.</td>  
            <td>Ashvini Kumar</td>  
            <td>ashvini@gmail.com</td>  
        </tr>  
        <tr>  
            <td>3.</td>  
            <td>Swati Sharma</td>  
            <td>swati8@gmail.com</td>  
        </tr>  
    </tbody>  
</table>  
</body>  
</html>  

Output:

HTML caption tag

Attribute

Tag-specific Attributes

AttributeValueDescription
aligntopbottomleftrightIt aligns the caption with respect to table

Global Attributes

The <caption> tag supports the Global attributes

Event Attributes

The <caption> tag supports the event attributes.

Supporting Browsers

Elementchrome browser Chromeie browser IEfirefox browser Firefoxopera browser Operasafari browser Safari
<caption>YesYesYesYesYes

Leave a Reply

Your email address will not be published. Required fields are marked *