---
title: "How do I make an HTML table accessible and responsive?"
description: "Give data tables a caption, proper th cells with scope, and wrap them in a scrollable region on small screens. Here is the markup and CSS, plus what to avoid."
url: https://www.danny.engineering/answer/html/how-do-i-make-an-html-table-accessible-and-responsive
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T20:30:00.000Z
tags: ["HTML"]
---

# How do I make an HTML table accessible and responsive?

## The short answer


Use real table markup: a `caption`, `thead` and `tbody`, and `th` cells with a `scope`. For small screens, wrap the table in a container that scrolls horizontally, and make that container focusable and labelled so keyboard users can scroll it too.


```html
<div class="table-scroll" role="region" aria-labelledby="plans-caption" tabindex="0">
  <table>
    <caption id="plans-caption">Plan comparison</caption>
    <thead>
      <tr>
        <th scope="col">Plan</th>
        <th scope="col">Price</th>
        <th scope="col">Users</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <th scope="row">Starter</th>
        <td>£5</td>
        <td>1</td>
      </tr>
      <tr>
        <th scope="row">Team</th>
        <td>£20</td>
        <td>10</td>
      </tr>
    </tbody>
  </table>
</div>
```


```css
.table-scroll {
  overflow-x: auto;
}
```


## Why it happens


Screen readers can move through a table cell by cell and announce the matching row and column headers as they go, for example "Team, Price, £20". That only works if the headers are marked up as `th` and the browser can work out which cells they belong to. A grid of `div` elements, or a table where every cell is a `td` with bold styling, gives none of that information.


Tables also do not shrink well. Their minimum width is the sum of their columns' minimum content, so on a phone a wide table either overflows the page and causes horizontal scrolling of the whole layout, or gets squashed until it is unreadable.


## How to fix it


### Add a caption


The `caption` element must be the first child of the `table`. It names the table, and screen readers announce it when the user enters the table. If the design has no visible title, you can visually hide the caption, but keep it in the markup.


### Mark up headers with th and scope


Use `th` for every header cell. Add `scope="col"` to column headers and `scope="row"` to row headers. Browsers can often guess simple cases, but `scope` removes the guesswork, especially when the first column is a header.


Group rows with `thead`, `tbody` and, if needed, `tfoot`. This also lets you style the header and footer without extra classes.


### Handle complex tables carefully


For headers that span several columns, use `colspan` and `scope="colgroup"`. For tables where a cell relates to headers that `scope` cannot express, give each `th` an `id` and list them in the cell's `headers` attribute.


```html
<th id="q1" scope="col">Q1</th>
<th id="north" scope="row">North</th>
<td headers="north q1">120</td>
```


If you find yourself doing this a lot, consider splitting the data into several simpler tables.


### Make the scroll container usable


The `overflow-x: auto` wrapper keeps the table from breaking the page layout. Three attributes make it accessible:

- `tabindex="0"` lets keyboard users focus the region and scroll it with the arrow keys.
- `role="region"` turns it into a landmark, which a focusable element needs so it has a meaningful role.
- `aria-labelledby` points at the caption so the region is announced by name.

Give the focused wrapper a visible outline, and consider a visual hint that more content is off to the side.


```css
.table-scroll:focus-visible {
  outline: 3px solid #2563eb;
  outline-offset: 2px;
}

.table-scroll th[scope='row'] {
  position: sticky;
  left: 0;
  background: white;
}
```


The sticky first column keeps row headers in view while the user scrolls sideways, which makes wide tables much easier to read.


### Reflow into cards only if you must


A common pattern turns each row into a stacked card on small screens by changing the table elements to `display: block`. This can work, but in some browsers changing the `display` value of table elements removes their table semantics, so screen readers no longer treat it as a table. If you use this pattern, test with a screen reader, or restore the roles with `role="table"`, `role="row"` and `role="cell"`. Horizontal scrolling is simpler and safer for most data.


## Common pitfalls

- **Using tables for layout.** Tables are for data with rows and columns. Use CSS grid or flexbox for layout.
- **Using a heading above the table instead of a caption.** A heading is fine for page structure, but the caption is what gets tied to the table.
- **Empty header cells.** A blank top-left `th` is common; use a `td` there instead, or give it text.
- **Setting overflow on the table itself.** Tables ignore `overflow`. Put it on a wrapper.
- **Hiding columns on mobile.** Removing data with `display: none` on small screens means some users never get it. Prefer scrolling.
- **Relying on colour or zebra stripes.** They help, but the header markup is what screen readers use.

## Related reading

- [MDN: The table element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/table)
- [MDN: The th element and scope](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/th)
