Caption

<caption>: The Table Caption element #

::: section-content The <caption> HTML element specifies the caption (or title) of a table. :::

Try it #

::: section-content ::: iframe ::: {.output-header .border-rounded-top}

HTML Demo: <caption> #

Reset :::

::: {#warning-no-script .warning-container} ::: warning The interactive example cannot be shown because JavaScript is disabled. ::: :::

::: {#warning-mathml-not-supported .warning-container .hidden} ::: warning The interactive example cannot be shown because MathML is not supported by your browser. ::: :::

::: {#editor-container .editor-container .tabbed-taller .hidden .border-rounded-bottom editor-type=“tabbed”} ::: {#tab-container .section .tabs} ::: {#tablist .tab-list role=“tablist”} HTML

CSS

JavaScript :::

::: {#html-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“html” aria-hidden=“true”} ::: {#html-editor}

He-Man and Skeletor facts
 He-ManSkeletor
RoleHeroVillain
WeaponPower SwordHavoc Staff
Dark secretExpert floristCries at romcoms
::: :::

::: {#css-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“css” aria-hidden=“true”} ::: {#css-editor} caption { padding: 10px; caption-side: bottom; }

table {
  border-collapse: collapse;
  border: 2px solid rgb(200, 200, 200);
  letter-spacing: 1px;
  font-family: sans-serif;
  font-size: 0.8rem;
}

td,
th {
  border: 1px solid rgb(190, 190, 190);
  padding: 7px 5px;
}

th {
  background-color: rgb(235, 235, 235);
}

td {
  text-align: center;
}

tr:nth-child(even) td {
  background-color: rgb(250, 250, 250);
}

tr:nth-child(odd) td {
  background-color: rgb(240, 240, 240);
}

.heman {
  font: 1.4rem molot;
  text-shadow:
    1px 1px 1px #fff,
    2px 2px 1px #000;
}

.skeletor {
  font: 1.7rem rapscallion;
  letter-spacing: 3px;
  text-shadow:
    1px 1px 0 #fff,
    0 0 9px #000;
}

::: :::

::: {#js-panel .section .hidden tabindex=“0” role=“tabpanel” aria-labelledby=“js” aria-hidden=“true”} ::: {#js-editor} ::: ::: :::

::: {#output .output-container}

Output #

::: :::

::: {.section .console-container .hidden aria-hidden=“true”}

Console Output #

![] clear console

::: {#console .console} ::: :::

::: {#html-output .output .editor-tabbed} %html-content% ::: ::: :::

Attributes #

::: section-content This element includes the global attributes. :::

Deprecated attributes #

::: section-content 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]{.visually-hidden}

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.

::: {#sect1 .notecard .warning} Warning: Do not use this attribute, as it has been deprecated. The <caption>{aria-current=“page”} element should be styled using the CSS properties caption-side and text-align. ::: :::

Usage notes #

::: section-content 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. :::

Example #

::: section-content This simple example presents a table that includes a caption.

::: code-example [html]{.language-name}

<table>
  <caption>
    Example Caption
  </caption>
  <tr>
    <th>Login</th>
    <th>Email</th>
  </tr>
  <tr>
    <td>user1</td>
    <td>user1@sample.com</td>
  </tr>
  <tr>
    <td>user2</td>
    <td>user2@sample.com</td>
  </tr>
</table>

:::

::: {#sect2 .code-example} ::: iframe ::: ::: :::

Technical summary #

::: section-content

Content categoriesNone.
Permitted contentFlow content.
Tag omissionThe end tag can be omitted if the element is not immediately followed by ASCII whitespace or a comment.
Permitted parentsA <table> element, as its first descendant.
Implicit ARIA rolecaption
Permitted ARIA rolesNo role permitted
DOM interfaceHTMLTableCaptionElement
:::

Specifications #

::: _table #

Specification #

HTML Standard
[# the-caption-element]{.small}


:::

Browser compatibility #

::: _table 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 :::

See also #

::: section-content

::: _attribution © 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{._attribution-link} :::