caption element represents a title or caption for the
table it's declared in, and is suposed to provide a very short but accurate description of its content or purpose. A good
caption should introduce context for a
table, making it significantly easier to understand.
caption element is usually displayed, by default, on top of the associated
table and with center-aligned text. This presentation can be altered using style sheets.
caption element can only be declared at the begining of the
table, before any other element inside it.
The following example shows a common use of the
caption element. As expected, it describes briefly the contents of the table.
<table class="egt"> <caption>Diameter and distance from the Sun for the inner planets</caption> <tr> <td></td> <th>Mercury</th> <th>Venus</th> <th>Earth</th> <th>Mars</th> </tr> <tr> <th>Diameter (kms)</th> <td>4,878</td> <td>12,104</td> <td>12,756</td> <td>6,787</td> </tr> <tr> <th>Distance from the Sun (millions of kms)</th> <td>57</td> <td>107</td> <td>150</td> <td>229</td> </tr> </table>
|Distance from the Sun (millions of kms)||57||107||150||229|
Note that this table has been formatted usign CSS to improove comprehension and readability. Authors shouldn't expect these results for tables with no presentational properties assigned.
A value indicating where the user agent should place the caption in relation with the table. It can take one of four case-insensitive values:
- top: on top of the table.
- bottom: under the table.
- left: at the left side of the table.
- right: at the right side of the table.
This attribute has become obsolete in HTML5 and its use is no longer valid. Authors are encouraged to use style sheets to provide presentational properties to the elements.
For information about global attributes refer to this list of global attributes in HTML5.
For information about global events refer to this list of global events in HTML5.