Computer Study

Caption Tag in HTML

The <caption> tag is an HTML element that is used to add a title or a brief explanation to a table. It is a child element of the <table> tag and must be placed immediately after the opening <table> tag.

The content of the <caption> tag is typically displayed at the top of the table and can be styled using CSS. The caption is usually used to provide a summary or a description of the data presented in the table, which can be helpful for users who are visually impaired and use screen readers to navigate the content.

Here’s an example of how to use the <caption> tag in HTML:

<table>
<caption>Employee Information</caption>
<thead>
<tr>
<th>Name</th>
<th>Department</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Smith</td>
<td>Marketing</td>
<td>$50,000</td>
</tr>
<tr>
<td>Jane Doe</td>
<td>Finance</td>
<td>$60,000</td>
</tr>
</tbody>
</table>

In the example above, the <caption> tag is used to provide a title for the table, “Employee Information”. The <thead> and <tbody> tags are used to define the header and body of the table, respectively, and the <th> and <td> tags are used to define the cells of the table.

Related Articles

Leave a Reply

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

Back to top button