Caption is a short description of anything so that it may be understood
what that thing is made for. In easy words, caption is the heading of
the table.
■ <caption> tag is used for this purpose.
■ It is used just after the opening tag of table element.
■ Important Attributes-
o align= (Optional)
It is used to align the caption with respect to the table. It may have following values-
- bottom
- center (Default)
- left
- right
- top
If change in the above code caption tag ie
■ <caption> tag is used for this purpose.
■ It is used just after the opening tag of table element.
■ Important Attributes-
o align= (Optional)
It is used to align the caption with respect to the table. It may have following values-
- bottom
- center (Default)
- left
- right
- top
Syntax
<caption align= "any value ie left ,right etc">any text</caption>
Example
1 Open Notepad
2 Copy code into Notepad
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<table border="4" bordercolor="red">
<caption align=top>Student Detail</caption>
<tr>
<th>Student Name</th>
<th>Roll Number</th>
<th>Class</th>
</tr>
<tr>
<td>vinod </td>
<td>01</td>
<td>BSC</td>
</tr>
<tr>
<td>Mohit </td>
<td>02</td>
<td>BSC</td>
</tr>
</table>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<table border="4" bordercolor="red">
<caption align=top>Student Detail</caption>
<tr>
<th>Student Name</th>
<th>Roll Number</th>
<th>Class</th>
</tr>
<tr>
<td>vinod </td>
<td>01</td>
<td>BSC</td>
</tr>
<tr>
<td>Mohit </td>
<td>02</td>
<td>BSC</td>
</tr>
</table>
</body>
</html>
3 Save as caption.html
4 Open file into any Browser
O/P
Student Name | Roll Number | Class |
---|---|---|
vinod | 01 | BSC |
Mohit | 02 | BSC |
If <caption align=bottom>Student Detail</caption>
Student Name | Roll Number | Class |
---|---|---|
vinod | 01 | BSC |
Mohit | 02 | BSC |
If change in the above code caption tag ie
<caption align=right>Student Detail</caption>
Student Name | Roll Number | Class |
---|---|---|
vinod | 01 | BSC |
Mohit | 02 | BSC |