Warning:
This wiki has been archived and is now read-only.

Elements/caption

From HTML Wiki
Jump to: navigation, search

<caption>

The <caption> element represents the title of the table that is its parent, if it has a parent and that is a table element.

Point

  • A caption can introduce context for a table, making it significantly easier to understand.
  • When a table element is the only content in a figure element other than the figcaption, the caption element should be omitted in favor of the figcaption. [Example B]


HTML Attributes

See global attributes.


Examples

Example A

[try it]

<table>
  <caption>
    <p>table 1. Sample table</p>
  </caption>
  <tr>
    <td>1</td>
    <td>2</td>
  </tr>
  <tr>
    <td>3</td>
    <td>4</td>
  </tr>
</table>

Example B

In the following example, the caption element is omitted in favor of the figcaption element. [try it]

<figure>
  <figcaption>
    <p>figure 1. Sample figure</p>
  </figcaption>
  <table>
    <caption>
      <p>table 1. Sample table</p>
    </caption>
    <tr>
      <td>1</td>
      <td>2</td>
    </tr>
    <tr>
      <td>3</td>
      <td>4</td>
    </tr>
  </table>
</figure>

HTML Reference

The HTML5 specification defines the <caption> element in 4.9.2 The caption element.