HTML/Elements/caption

From Web Education Community Group
< HTML‎ | Elements
Revision as of 13:19, 19 November 2011 by Rworth (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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>

Caption01.png

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.