Skip to main content

HTML Tags

HTML <caption> Tag

Written by Updated HTML <caption> Tag exercises

<caption> is a table's title. It must be the first child of the <table>, it is announced by screen readers as the table's name, and it stays attached to the table when the table scrolls, moves or is copied. A heading placed above the table does none of that.

Try it

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>caption</title>
  <style>
    table { border-collapse: collapse; font-family: system-ui; }
    caption { caption-side: top; text-align: left; font-weight: 600; padding: 0 0 8px; }
    th, td { border-bottom: 1px solid #e2e8f0; padding: 6px 14px; text-align: left; }
    td { text-align: right; }
  </style>
</head>
<body>
<table>
  <caption>Practice completed this week</caption>
  <thead>
    <tr><th scope="col">Day</th><th scope="col">Exercises</th><th scope="col">Minutes</th></tr>
  </thead>
  <tbody>
    <tr><th scope="row">Mon</th><td>3</td><td>25</td></tr>
    <tr><th scope="row">Tue</th><td>5</td><td>40</td></tr>
    <tr><th scope="row">Wed</th><td>2</td><td>15</td></tr>
  </tbody>
</table>
</body>
</html>

Change caption-side: top to bottom and run again. The caption moves below the table without touching the HTML: that is the one CSS property specific to it.

Why not just a heading?

Visually, <h3>Practice completed this week</h3> above the table looks identical. The difference is in what is not visible. A screen reader user navigating by table hears "table, Practice completed this week, 4 rows, 3 columns" when the caption is there; with a heading they hear "table, 4 rows, 3 columns" and have to go looking for what it is. A page with several tables (a pricing page, a results page) becomes a list of unnamed tables. The caption is also what a browser's reader mode, a copy-paste into a document, and a search engine's table extraction treat as the title.

You can have both: a heading for the section, a caption for the table. If the heading already says exactly what the table is, you can link them instead, aria-labelledby on the <table> pointing at the heading's id, but a caption is simpler and needs no attributes.

Rules

  • It must be the first child of <table>, before <thead>, <colgroup>, or any <tr>.
  • One caption per table. A second one is invalid and ignored.
  • It can contain any inline content (text, a link, <em>) and even block content, though a single line is usual.
  • It has no attributes of its own. align is obsolete; use caption-side and text-align.

A realistic example: a caption that carries the units and the source

Good captions do more than name the table. Putting the unit and the data source in the caption keeps the cells clean and means nobody has to guess what "40" is.

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Descriptive caption</title>
  <style>
    table { border-collapse: collapse; font-family: system-ui; }
    caption { text-align: left; padding-bottom: 8px; font-weight: 600; }
    caption small { display: block; font-weight: normal; color: #64748b; margin-top: 2px; }
    th, td { border-bottom: 1px solid #e2e8f0; padding: 6px 14px; text-align: left; }
    td { text-align: right; font-variant-numeric: tabular-nums; }
  </style>
</head>
<body>
<table>
  <caption>
    Average time to first solve, in minutes.
    <small>Learners who finished the chapter, Jan–Aug 2026.</small>
  </caption>
  <tr><th scope="col">Chapter</th><th scope="col">Exercise</th><th scope="col">Bug fix</th></tr>
  <tr><th scope="row">Flexbox</th><td>7.5</td><td>11.2</td></tr>
  <tr><th scope="row">Grid</th><td>9.1</td><td>13.8</td></tr>
  <tr><th scope="row">Closures</th><td>12.4</td><td>16.0</td></tr>
</table>
</body>
</html>

Styling

caption-side: top | bottom positions it. Browsers centre it by default; text-align: left usually reads better over a left-aligned table. It takes padding, color, font and background like any block. It sits outside the table's border box, so a border on <table> does not enclose it: if you want the caption inside a framed card, put the border on a wrapping <div> instead.

Common mistakes

1. Not first

<table><tr>…</tr><caption>Title</caption></table> is invalid. Browsers usually still display it at the top, but the DOM is repaired differently across browsers and assistive technology may not associate it. It goes immediately after the opening <table> tag, before everything.

2. A caption that repeats the heading word for word

Heading "Pricing", caption "Pricing". Screen readers announce both. Either drop the heading, or make the caption do real work: "Monthly and yearly prices in INR, excluding GST".

3. Hiding it with display: none

If the design has no room for a visible caption, hiding it with display: none hides it from screen readers too. Use a visually-hidden utility class (the sr-only pattern) so the name remains available.

4. Using it as a figure caption

<caption> belongs only to <table>. A caption for an image, chart or code block is <figcaption> inside a <figure>. You can wrap a table in a <figure> and give it a <figcaption> as well, for a longer note, but the table's own name should still be a <caption>.

Browser support

Universal, including caption-side.

Related chapters

HTML <caption> Tag exercises

Caption a table

Make a table with one cell, Ada, and the caption Team members.

Result

Check your answer to see it here.