Caption HTML

HTML <caption> Tag

To add a caption or a title to a table in HTML, the HTML <caption> tag is used. It is placed just after the <table> start tag and inside the <table> element. Usually, there is only one <caption> element is present in an HTML table.

Syntax:

<caption>Title of Table</caption>

Example:

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 2px solid brown;
}
</style>
</head>
<body>
<table width="400">
  <caption>Students Details</caption>
  <tr>
    <th>ID</th>
    <th>NAME</th>
    <th>SUBJECT</th>
  </tr>
  <tr>
    <td>101</td>
	<td>Yash Panwar</td>
    <td>Mathematics</td>
  </tr>
  <tr>
   <td>201</td>
	<td>Janny Singh</td>
    <td>Biology</td>
  </tr>
  <tr>
   <td>301</td>
	<td>Ankita Das</td>
    <td>Accounts</td>
  </tr>
</table>
</body>
</html>

Output:

Explanation:

In the above example, we are creating a table in HTML and than adding a caption to it using the HTML <caption> tag.

Tag specific Attributes:

Attribute Value Uses
align top

bottom

left

right

To specify the alignment of a caption with respect to the table.

Global Attributes:

The HTML global attributes are supported by the HTML <caption> tag.

Event Attributes:

The HTML event attributes are supported by the HTML <caption> tag.

Supporting Browsers:

Chrome, IE, Firefox, Opera and Safari.

Please Share