Summary -

In this topic, we described about the <caption> tag along with detailed example.

Used to specify the caption or title for a table. The <caption> tag is used to define table captions. If the <caption> tag used with table, it would be the first tag before any other table tag.

The caption can be as long as like paragraph or short titles. Any text inserted in between <caption></caption> will be treated as caption for the tag.

Only one caption needs to be associated with table, but not more than one. The align attribute was removed from HTML5.

Syntax -

<caption>.. text here.. </caption>

Optional Attributes -

AttributeDescriptionValues
Align Specifies the caption alignment.Not supported in HTML5 LeftRightTopbottom

Example -

<!DOCTYPE html>
<html>
	<head>
		<title> Caption element example.. </title>
	</head>
	<body>
		<table>
			<caption>Employee details</caption>
			<tr>
				<th>EMP name</th>
				<th>Designation</th>
			</tr>
			<tr>
				<td>Pawan</td>
				<td>Lead</td>
			</tr>
		</table>
	</body>
</html>

Output -

Employee details
EMP name Designation
Pawan Lead