HTML <caption> tag

The <caption> tag is used to create a table caption. Captions appear at the top of a table by default.

NOTE: The <caption> tag should be placed right below the <table> tag before the first <tr> tag.

Attributes

Attribute Possible values Description
align left, right, top, bottom Deprecated. Sets how a caption will be aligned

Firefox is the only one of the major browsers that properly supports the align attribute. All the major browsers support top and bottom alignment of a caption, left and right alignment of a caption is not supported at all in Chrome or Safari, and only the text inside the caption (as opposed to the entire caption element) is aligned in Internet Explorer and Opera.

Standard attributes

class, dir, id, lang, style, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

onclick, ondblclick, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup, onkeydown, onkeypress, onkeyup

For more information on event attributes, check out our HTML event attributes reference page.

Example

NOTE: The below example will appear correctly only in Firefox

<table border="2"> <caption align="left">Amount of customers</caption> <tr> <th>Month</td> <td>Total</td> </tr> <tr> <td>January</td> <td>1000</td> </tr> <tr> <td>February</td> <td>1200</td> </tr> </table>
Output:
Amount of customers
Month Total
January 1000
February 1200

Tips & notes

Having a caption for a table is a good usability practice - it makes your content look more organized. But be sure to style the caption to distinguish it from other elements on a page.

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation