AD JB Toolbox 01 EN

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

A readable data table identifies its subject and makes clear which row and column headings apply to each value. Use caption and th, add scope where it helps, and merge cells only when the resulting relationships remain understandable.

Name the table with caption

caption describes the table as a whole and belongs at the beginning of table. It differs from a nearby paragraph heading because it is part of the table. If a period or measurement method is needed to interpret the numbers, state it in the caption or nearby text. The caption introduces the table; individual row and column names still belong in header cells.

Connect data to headers with scope

Use scope="col" for column headings and scope="row" for row headings. In this example, the value at Monday and Morning is three visitors.

<table>
  <caption>Visitors by day and time of day</caption>
  <thead>
    <tr>
      <th scope="col">Day</th>
      <th scope="col">Morning</th>
      <th scope="col">Afternoon</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Monday</th>
      <td>3 visitors</td>
      <td>5 visitors</td>
    </tr>
    <tr>
      <th scope="row">Tuesday</th>
      <td>4 visitors</td>
      <td>6 visitors</td>
    </tr>
  </tbody>
</table>
Visitors by day and time of day
Day Morning Afternoon
Monday 3 visitors 5 visitors
Tuesday 4 visitors 6 visitors

scope describes the direction of a header's relationship to data; it is not a visual styling rule. In a simple table, the relationship may be obvious without it, but explicit markup makes the intent easier to review. The W3C WAI tables tutorial explains further patterns.

Merge cells only when the data requires it

colspan="2" covers two columns; rowspan="2" covers two rows. The next example groups Morning and Afternoon under a shared heading. The colgroup defines those two columns so scope="colgroup" has a clear target.

<table>
  <col>
  <colgroup span="2"></colgroup>
  <tr>
    <th scope="col" rowspan="2">Day</th>
    <th scope="colgroup" colspan="2">Visitors</th>
  </tr>
  <tr>
    <th scope="col">Morning</th>
    <th scope="col">Afternoon</th>
  </tr>
  <tr>
    <th scope="row">Monday</th>
    <td>3 visitors</td>
    <td>5 visitors</td>
  </tr>
</table>

Do not add merged cells simply to decorate a straightforward table. If readers have to guess which heading belongs to a number, simplify the table or split it into smaller tables. The W3C WAI guide to irregular table headers gives more complex examples.

Test the relationships

Point to any value and ask, “Which day and time does this represent?” Check the answer without relying only on color or position. Test narrow screens for clipped content and, for complex merged tables, try a screen reader as well. Tables should represent data, not a page layout or an input form.

More in This Category
HTML Tutorial / Images: img, Alt Text, and Dimensions

HTML Tutorial / Images: img, Alt Text, and Dimensions

Add an image with HTML img, write useful alternative text, and set width and height correctly. A downloadable example helps you test file paths and sizing.

HTML Tutorial / Basic Structure of an HTML Document

HTML Tutorial / Basic Structure of an HTML Document

Learn the roles of doctype, html, head, and body, then save your first HTML file and open it in a browser. Includes a complete example, a diagram, and fixes for common filename, refresh, and encoding problems.

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

Make table headings and data relationships clear with caption, th, and scope, and learn when colspan or rowspan makes a table harder to read.

HTML Tutorial / Headings and Paragraphs

HTML Tutorial / Headings and Paragraphs

Learn when to use h1–h6 headings, p paragraphs, and br line breaks in HTML. Examples show document hierarchy, browser output, and common mistakes.

HTML Tutorial / When to Use div and span

HTML Tutorial / When to Use div and span

Understand the structural difference between div and span, style only the content you need, and choose semantic elements when they better describe the content.

HTML Tutorial / Links: Paths, Page Fragments, and Email

HTML Tutorial / Links: Paths, Page Fragments, and Email

Create HTML links with absolute or relative URLs, jump to a document fragment, and add email, new-tab, or download links. Learn what to verify before publishing.

HTML Tutorial / Table Basics: table, tr, th, and td

HTML Tutorial / Table Basics: table, tr, th, and td

Build a basic HTML data table with rows and header or data cells, then organize its headings and body without using tables for page layout.

HTML Tutorial / Lists: ul, ol, dl, and Nested Lists

HTML Tutorial / Lists: ul, ol, dl, and Nested Lists

Choose the right HTML list for ordered items, unordered items, and name–description pairs. Try a complete example, custom numbering, and correctly nested lists.

HTML Tutorial / Divide a Page with Semantic Elements

HTML Tutorial / Divide a Page with Semantic Elements

Learn when to use header, nav, main, article, section, aside, and footer, then build a complete page whose regions and in-page links work together.

HTML Tutorial / What Is HTML and What Does It Do on a Web Page?

HTML Tutorial / What Is HTML and What Does It Do on a Web Page?

HTML gives web content structure and meaning. Learn how it differs from CSS and JavaScript, see how basic markup appears in a browser, and make your first HTML file.