Course contentsShow
← Web Development
Lesson 113 of 2,9822. HTML FundamentalsFree lesson

Table Caption with <caption>

Add accessible titles to tables that describe their purpose.

Table Caption with <caption>

What you'll learn: How to add a descriptive title to your HTML tables that explains what the table data represents.


What is a Table Caption?

A <caption> element provides a visible title or description for your table. Think of it like the headline on a chart in a newspaper—it tells readers what they're looking at before they dive into the details. While the data inside a table might be clear to you, visitors (and especially screen reader users) benefit from a clear explanation of what the table contains.

How to Use <caption>

The <caption> element must be the first child inside your <table> element, appearing immediately after the opening <table> tag and before any rows or headers:

<table>
  <caption>Monthly Sales Report for Q1 2024</caption>
  <tr>
    <th>Month</th>
    <th>Revenue</th>
  </tr>
  <tr>
    <td>January</td>
    <td>$5,000</td>
  </tr>
  <tr>
    <td>February</td>
    <td>$6,200</td>
  </tr>
</table>

Why This Matters

The caption serves two important purposes:

  1. Accessibility: Screen readers announce the caption first, giving users context before they navigate through the table data
  2. Clarity: Sighted users immediately understand the table's purpose without having to read through all the data first

You can only have one <caption> per table, and it's positioned above the table by default (though CSS can change this later).


Key Takeaway: Use the <caption> element as the first child of <table> to provide an accessible, descriptive title that explains what your table data represents.