English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag大全

HTML: <caption> Tag

HTML <caption> tag defines the table title in the HTML document. Traditionally, browsers render the text found in the <caption> tag at the top of the table, but you can use CSS caption-side attribute changes this behavior. This tag is also commonly referred to as the <caption> element.

The HTML <caption> element (or HTML table title element) displays a table title, which is often the first child of <table> and appears at the beginning of the table content, but it can also be styled with CSS, so it can appear at any position relative to the table.

Online example

Table with caption title:

!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic Tutorial Website(oldtoolbag.com)</title> 
</head>
<body>
<table>
  <caption>This is the caption for the table</caption>
  <tr>
    <th>Column 1 Heading</th>
    <th>Column 2 Heading</th>
    <th>Column 3 Heading</th>
  </tr>
  <tr>
    <td>Data in Column 1, Row 2</td>
    <td>Data in Column 2, Row 2</td>
    <td>Data in Column 3, Row 2</td>
  </tr>
  <tr>
    <td>Data in Column 1, Row 3</td>
    <td>Data in Column 2, Row 3</td>
    <td>Data in Column 3, Row 3</td>
  </tr>
  <tr>
    <td>Data in Column 1, Row 4</td>
    <td>Data in Column 2, Row 4</td>
    <td>Data in Column 3, Row 4</td>
  </tr>
</table>
</body>
</html>
Test to see ‹/›
In this HTML5In the document example, we used the <table> tag to create a table. The first tag of <table> is <caption>. Then the table has3and4rows. The column of the table is1defined by the first <tr> tag. It has3A table header cell defined by the <th> tag. The row of this table is2to4Rows are defined using the <td> tag to define standard table cells.

Browser compatibility

IEFirefoxOperaChromeSafari

All mainstream browsers support the <caption> tag.

Label definition and usage instructions

The HTML <caption> element is located within the <body> tag.
The <caption> tag appears as the first tag after the <table> tag.

The <table> tag is composed of <tr>, <th>, and <td> tags.

Most browsers will display the <caption> tag above the table, but you can use CSS caption-The side attribute changes this behavior.

The <caption> tag defines the title of the table.

The <caption> tag must be placed directly after the <table> tag.

Note: Only one title can be specified for each table.

Tip: By default, the table title will be centered above the table. However, you can use CSS text-align and caption-side can be used for alignment and placement of the title.

HTML 4.01 and HTML5Differences between

The align attribute has been removed from HTML5Removed from HTML

Attribute

AttributeValueDescription
alignleft
right
top
bottom

HTML5 Not supported. HTML 4.01 Deprecated.    Defines the alignment of the title.
It can be one of the following values:
left-Represents the title appearing in the table
top -Represents the title appearing in the table
right -Represents the title appearing in the table
bottom -Represents the title appearing below the table at the bottom

Global Attributes

Support for <caption> tag Global Attributes of HTML.

Event Attributes

Support for <caption> tag HTML Event Attributes.