Skip to content

Table Captions

A caption line can be placed immediately before or after the table. The syntax is [Caption text] or [Caption text][label].

Caption before the table

When placed before the table, the caption renders at the top.

[Sales Data]
| Q1   | Q2   | Q3   | Q4   |
| ---- | ---- | ---- | ---- |
| 100  | 120  | 95   | 140  |
Sales Data
Q1 Q2 Q3 Q4
100 120 95 140
<table><caption id="salesdata">Sales Data</caption><thead>
<tr>
<th>Q1</th>
<th>Q2</th>
<th>Q3</th>
<th>Q4</th>
</tr>
</thead>
<tbody>
<tr>
<td>100</td>
<td>120</td>
<td>95</td>
<td>140</td>
</tr>
</tbody>
</table>

Caption after the table

When placed after the table, the caption renders at the bottom (using caption-side: bottom).

| Q1   | Q2   | Q3   | Q4   |
| ---- | ---- | ---- | ---- |
| 100  | 120  | 95   | 140  |
[Annual Sales]
Annual Sales
Q1 Q2 Q3 Q4
100 120 95 140
<table><caption id="annualsales" style="caption-side: bottom">Annual Sales</caption><thead>
<tr>
<th>Q1</th>
<th>Q2</th>
<th>Q3</th>
<th>Q4</th>
</tr>
</thead>
<tbody>
<tr>
<td>100</td>
<td>120</td>
<td>95</td>
<td>140</td>
</tr>
</tbody>
</table>

Auto-generated ID (autolabel)

When autolabel is enabled (default), the caption text is lowercased and stripped of non-word characters to form the id attribute.

[Hello, World! 2024]
| A |
| - |
| 1 |
Hello, World! 2024
A
1
<table><caption id="helloworld2024">Hello, World! 2024</caption><thead>
<tr>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
</tr>
</tbody>
</table>

The generated id attribute will be helloworld2024.

Explicit label

Provide a custom id with the [text][label] syntax:

[My Table][tbl-sales]
| Q1   | Q2   |
| ---- | ---- |
| 100  | 120  |
My Table
Q1 Q2
100 120
<table><caption id="tblsales">My Table</caption><thead>
<tr>
<th>Q1</th>
<th>Q2</th>
</tr>
</thead>
<tbody>
<tr>
<td>100</td>
<td>120</td>
</tr>
</tbody>
</table>

An explicit label always overrides the auto-generated one, even when autolabel is enabled.

Disabling autolabel

Set autolabel: false in the configuration to suppress automatic ID generation. Captions without an explicit label will then have no id attribute.

markdown_extensions:
  - pymdown_multimd_table:
      autolabel: false