Add a caption to a Markdown table

How to caption a Markdown table: which flavors support caption syntax, when to use an HTML caption element, and how each option affects accessibility and portability.

Short answer

Standard Markdown has no caption syntax for tables. CommonMark does not define tables, and the GitHub Flavored Markdown table extension defines rows, a header and column alignment, but no caption. You can add a caption in one of three ways. You can use a flavor that has its own caption syntax, such as Pandoc or MultiMarkdown. You can write the whole table in HTML with a caption element. Or you can put a plain bold or italic label above the table. The first two options link the caption to the table in the output. The third only looks like a caption. Choose based on where the file will be rendered. If you don't control the renderer, or the file has to stay readable as raw text, a plain label is the safer choice.

What a caption actually changes

A real table caption is a change to the document's structure, not to its appearance. In HTML it is a caption element placed as the first child of the table element. Browsers and assistive technologies use that element as the table's name. A bold line above the table is only formatting. It is an ordinary paragraph that happens to sit nearby, and software has no reliable way to tell that it describes the table. This difference matters more than how the caption looks. CSS can make either version look the same, but only the caption element is tied to the table in the markup.

Some editors and authors use the words 'caption', 'title' and 'heading' interchangeably. In this article, 'caption' means a label that the output format attaches to the table. A heading placed before the table belongs to the document outline instead. That can be useful, but it is not the same thing.

Which Markdown flavors support captions

Approach | Caption syntax | What the output contains
CommonMark | None (no table syntax) | Not applicable
GitHub Flavored Markdown | None in the table extension | Any label you add is a separate paragraph
Pandoc | A paragraph starting with "Table:" or ":" placed before or after the table | A caption element in HTML output; a native caption in formats such as LaTeX
Quarto (built on Pandoc) | Pandoc-style ":" caption line, optionally with a cross-reference ID | A captioned table that can be cross-referenced
MultiMarkdown | Caption text in square brackets on the line directly before or after the table | A caption element in HTML output
Raw HTML inside Markdown | A caption element inside a full HTML table | Whatever the destination's HTML sanitizer allows through

Pandoc caption, with a blank line separating it from the table:

| Shortcut | Action |
|----------|--------|
| Ctrl+B   | Bold   |
| Ctrl+I   | Italic |

Table: Common editor shortcuts

MultiMarkdown caption, on the line directly after the table:

| Shortcut | Action |
| -------- | ------ |
| Ctrl+B   | Bold   |
| Ctrl+I   | Italic |
[Common editor shortcuts]

HTML table with a caption element:

<table>
  <caption>Common editor shortcuts</caption>
  <thead>
    <tr><th>Shortcut</th><th>Action</th></tr>
  </thead>
  <tbody>
    <tr><td>Ctrl+B</td><td>Bold</td></tr>
    <tr><td>Ctrl+I</td><td>Italic</td></tr>
  </tbody>
</table>

You cannot reliably put a caption element in HTML and then follow it with a Markdown pipe table inside the same table element. CommonMark-based parsers treat the HTML as a raw block, so the Markdown rows inside it are usually left unparsed. If you choose HTML, write the entire table in HTML.

How each option degrades in the wrong renderer

Caption syntax is specific to each flavor, so think about what happens when a file ends up somewhere else. A Pandoc caption line rendered by a GFM renderer shows up as an ordinary paragraph that starts with "Table:". It stays readable, but the prefix is visible. A MultiMarkdown bracket caption shows up as literal text in square brackets. If the document happens to contain a link reference definition with the same text, it could even be read as a link. An HTML table depends on the destination accepting raw HTML. Some platforms strip all HTML. Others keep table elements but may remove particular tags or attributes. A plain bold label renders more or less the same everywhere, which is why it is the most portable choice, even though it has no structural meaning.

Readability, copying and accessibility

  • Assistive technology: a caption element gives the table a programmatic name. The W3C's WCAG technique H39 describes using caption elements to associate a caption with a data table. Screen readers commonly announce the caption when a user moves into the table, but behavior varies by screen reader and browser. Test the combinations your readers use rather than assuming a particular result.
  • A bold label above the table provides no association. A screen reader user moving through tables will hear the table without its label, unless the label is also exposed some other way.
  • Reading order: in the HTML output, the caption is the first child of the table no matter where it appears visually. CSS caption-side can move it below the table on screen, but it does not change the order in the source.
  • Copy and paste: copying a rendered table into a spreadsheet or another editor may or may not bring the caption along. That depends on the source application and the destination. If the caption carries essential context, such as units or the date range of the data, repeat that context in the surrounding text or in the column headers.
  • Search and editing: a caption is ordinary text in every one of these approaches, so it stays searchable and editable. No characters are substituted or styled in a way that would break find-and-replace.
  • Raw-source readability: Pandoc and MultiMarkdown captions stay easy to read in the plain .md file. A full HTML table is much harder to scan and edit by hand, which matters in repositories where people review the raw diff.

When a plain-text label is the better choice

Use a plain bold or italic label, or a short heading, in these situations:
• The file will be shown on platforms you don't control.
• The destination strips HTML.
• Collaborators need to edit the raw source comfortably.
Use native caption syntax when you control the toolchain, for example when you build documents with Pandoc or Quarto, and you need numbered captions, cross-references or accessible output. Use an HTML caption element only when you must target a GFM-style renderer, you need the structural link, and you have confirmed that the destination keeps the element.

What this review could not verify

  • No rendering tests were run for this article. Whether a specific hosting platform, wiki or static site generator keeps a caption element after sanitization has to be checked in that environment.
  • Screen reader announcements differ between products and versions. No particular screen reader's behavior is confirmed here.
  • Copy-and-paste behavior between specific editors, browsers and spreadsheet applications was not tested.
  • Other Markdown processors may offer caption extensions not covered here. Check your processor's documentation before you rely on any syntax.