Description

The HTML element <caption> is used to define a title of a table, which describes the table content.

The element <caption> must follow the below rules.

  • Only one <caption> element must be defined within the <table> element.
  • The element <caption> must be included immediately after the <table> element before the table row elements <tr> start.

The below table summarizes its usage.

Usage Details
Placement It is displayed as an Inline element.
Contents It can contain Inline elements and text.
Tags Both the opening and closing tags are required.
Versions HTML 3.2, 4, 4.01, and 5

Syntax

Here is the basic syntax of the <caption> element.

<caption>...</caption>

Examples

In the below example, the <caption> element is included immediately after the <table> element with a title that describes the table content.

<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
    <h1>HTML Element - caption</h1>
    <table>
        <caption>Product Details</caption>
        <tr>
            <th>Product</th>
            <th>Sales</th>
        </tr>
        <tr>
            <th>Bread</th>
            <th>10000</th>
        </tr>
        <tr>
            <th>Butter</th>
            <th>3000</th>
        </tr>
    </table>
</body>
</html>

Attributes

The following table shows the list of supported and unsupported attributes for the <caption> tag.

Attribute Type Details
Element-Specific Attributes The tag <caption> has some element-specific attributes listed in the below table.
Global Attributes Like all other HTML tags, the tag <caption> supports the HTML Global Attributes.
Event Attributes The tag <caption> also supports the HTML Event Attributes.

Here is a list of attributes that are specific to the <caption> element.

Attribute Value Description
align top, bottom, left, right Specifies the title position with respect to table content.
This is obsolete and not valid for HTML5.

Browser Compatibility

The tag <caption> is supported in all modern browsers.

  • Google Chrome 1+
  • Internet Explorer or Edge 4+
  • Firefox 1+
  • Apple Safari 1+
  • Opera 4+

Related Links