The <caption>
HTML element specifies the caption (or title) of a table.
The <caption>
HTML element specifies the caption (or title) of a table.
This element includes the global attributes.
The following attributes are deprecated and should not be used. They are documented below for reference when updating existing code and for historical interest only.
align
Deprecated
This enumerated attribute indicates how the caption must be aligned with respect to the table. It may have one of the following values:
left
The caption is displayed to the left of the table.
top
The caption is displayed above the table.
right
The caption is displayed to the right of the table.
bottom
The caption is displayed below the table.
Warning: Do not use this attribute, as it has been deprecated. The <caption>
element should be styled using the CSS properties caption-side
and text-align
.
If used, the <caption>
element must be the first child of its parent <table>
element.
When the <table>
element that contains the <caption>
is the only descendant of a <figure>
element, you should use the <figcaption>
element instead of <caption>
.
A background-color
on the table will not include the caption. Add a background-color
to the <caption>
element as well if you want the same color to be behind both.
This simple example presents a table that includes a caption.
html
<table> <caption> Example Caption </caption> <tr> <th>Login</th> <th>Email</th> </tr> <tr> <td>user1</td> <td>[email protected]</td> </tr> <tr> <td>user2</td> <td>[email protected]</td> </tr> </table>
Content categories | None. |
---|---|
Permitted content | Flow content. |
Tag omission | The end tag can be omitted if the element is not immediately followed by ASCII whitespace or a comment. |
Permitted parents | A <table> element, as its first descendant. |
Implicit ARIA role | caption |
Permitted ARIA roles | No role permitted |
DOM interface | HTMLTableCaptionElement |
Specification |
---|
HTML Standard # the-caption-element |
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
caption |
1 | 12 | 1 | Yes | 15 | ≤4 | 4.4 | 18 | 4 | 14 | ≤3.2 | 1.0 |
align |
1 | 12 | 1 | Yes | 15 | ≤4 | 4.4 | 18 | 4 | 14 | ≤3.2 | 1.0 |
<caption>
element:
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/caption