XML technologies / CSS / CSS Cookbook / Tables / Styling table captions

(Excerpt from “CSS Kochbuch” by Christopher Schmitt)

Problem

A table’s description (caption) should have its own styles.

Solution

Use the element selector caption:

table caption {
 font: 1.5em Georgia, "Times New Roman", Times, serif;
 padding: 1em;
}

Discussion

Captions explain a table’s contents and should appear in the HTML code after the opening table element, but before all other elements such as thead or tr:

<table id="shoppingcartTable" summary="Liste der Produkte in Ihrem Warenkorb.">
  <caption>Ihr Warenkorb - <strong>Summe: 45,16 ¤</strong>; Menge ändern <input type="submit" value="Preis(e) aktualisieren" /></caption>
  ...
</table>

Although the appearance of the element caption may differ between browsers, all browsers display it. It can be styled with CSS and is the most accessible way to add captions to tables.

See also

The HTML 4.01 specification for the property caption.

  

 

 

 

back to top