Learn HTML – Part 36 – caption Tag – Table Title
The HTML caption tag is used to define a title or heading for an HTML table.
It provides a brief description of the table’s content, helping users understand the purpose of the data.
What is the caption Tag?
The caption tag is used inside the table element to define the table title.
The caption is usually displayed above the table.
Basic Syntax
<table>
<caption>Student Information</caption>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
</table>
Example – Table with Caption
<table border="1">
<caption>Student Details</caption>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Alice</td>
<td>23</td>
</tr>
<tr>
<td>Bob</td>
<td>28</td>
</tr>
</table>
Output:
| Name | Age |
|---|---|
| Alice | 23 |
| Bob | 28 |
Important Rules for caption
- The
captionelement must be placed immediately after the openingtabletag. - A table should have only one caption.
- It describes the purpose of the table.
Why Use the caption Tag?
- Provides a clear title for the table
- Improves accessibility for screen readers
- Helps users understand the table content quickly
- Improves semantic HTML structure
The
captiontag helps describe the data displayed in a table.
Common Mistakes Beginners Make
- Placing the caption outside the table
- Using multiple captions in a table
- Not providing meaningful titles
Conclusion
The HTML caption tag is used to define a title for an HTML table.
It helps users quickly understand the purpose of the table and improves accessibility.
What’s Next?
Now that you understand the caption tag, the next step is learning about the form tag, which is used to create forms for collecting user input.
Next: Learn HTML – Part 37 – form Tag – Creating HTML Forms →
Series: Learn HTML Series
