CSS Reference ยท Lists, Tables and Generated Content
The caption-side property
Reference for the CSS caption-side property: place a table caption above or below its table, with live examples, value table, usage notes and browser support.
The caption-side property decides on which side of a table the <caption> is drawn. By default the caption sits above the table, which is what most readers expect for a title. Setting it to bottom moves the caption below the table, which suits source notes and figure-style labels such as "Table 2: Quarterly totals".
The caption is a box of its own that is as wide as the table box. Because it is separate from the rows, text-align, padding and color set on the caption work the way they do on any block.
caption { caption-side: bottom; }
Try it
Syntax
caption-side: top | bottom; caption-side: block-start | block-end | inline-start | inline-end;
- Initial value:
top - Applies to: table caption boxes (
display: table-caption, normally the<caption>element) - Inherited: yes
- Animatable: no (the value changes in a single step)
- Computed value: as specified
Values
| Value | Description |
|---|---|
top |
Draws the caption above the table. This is the default. |
bottom |
Draws the caption below the table. |
block-start, block-end |
Logical versions that follow the writing mode. In horizontal text they match top and bottom. |
inline-start, inline-end |
Logical versions for the inline direction. Support is much thinner than for top and bottom. |
Usage notes
- Keep the
<caption>as the first child of the<table>in your HTML, even when you show it at the bottom. The markup order is what assistive technology uses;caption-sideonly changes the visual position. - The property is inherited, so you can set it on a
tableor a wrapper once instead of on every caption. - A caption is not part of the table grid. Its width follows the table width, and long text wraps inside that width instead of stretching the table.
- To change the gap between caption and table, use
paddingon the caption.marginon a caption behaves inconsistently across layouts, so avoid depending on it. - Prefer
topandbottomunless you really need writing-mode-aware behavior; check a compatibility table before relying on the logical keywords.
Browser support
top and bottom work in every browser; the logical keywords (block-start and friends) are newer, so check a compatibility table before using them.
Related
border-collapseโ merge or separate cell bordersborder-spacingโ the gap between separated cellsempty-cellsโ show or hide empty cells- Lesson: Styling Tables