w3resource

HTML caption tag and element

HTML caption element

1. HTML caption element contains a text describing the nature of the table.

2. caption element can be placed immediately after the start tag of the table.

3. A table can contain only one caption.

4. caption element starts with <caption> tag and ends with </caption> tag.

Syntax

 <caption>text content </caption> 

Category

HTML caption element is a part of HTML Tables.

Whether both start and end tags are required

Yes.

Can contain

HTML caption element can contain a piece of text only..

Can reside within

HTML caption element can reside within table element.

Attributes

Attributes specific to this element

None.

Identifiers

id, class.

language information and text direction

lang, dir.

Title

Title.

Style

Style.

Events

onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup.

Supported doctypes

HTML 4.01 Strict, HTML 4.01 Transitional, and HTML 4.01 Frameset.

Example of using HTML caption element

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>html caption tag example</title>
</head>
<body>
<table border="1">
<caption>First column holds Student code and second column holds percentage of marks obtained by the student</caption>
<tr> 
<th>Student code </th>
<th>% of marks </th>
</tr>
<tr> 
<td>S001</td>
<td>85</td>
</tr>
<tr> 
<td>S002</td>
<td>86</td>
</tr>
<tr> 
<td>S003</td>
<td>72</td>
</tr>
<tr> 
<td>S004</td>
<td>89</td>
</tr>
</table>
</body>
</html>

View this example in a separate browser window

HTML caption tag example.

Pictorial presentation

html caption tag

Previous: HTML table tag and element
Next: HTML thead tag and element

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/html/caption/HTML-caption-tag-and-element.php