How to Create Accessible HTML Tables With thead, th and caption

Build HTML data tables that screen readers understand and phones can display, with the right structure, clean CSS, and a quick way to convert spreadsheet data.

Updated September 29, 2026 5 min read

Use the free HTML Table GeneratorBuild HTML tables visually or paste from Excel, get clean code

A pricing comparison, a delivery schedule, a list of office opening hours: tabular data is everywhere on websites, and it often ends up as a screenshot of a spreadsheet or a pile of <div> elements styled to look like a grid. Both look fine to some visitors and fail others. Screenshots cannot be read by screen readers, searched or zoomed cleanly; div grids lose the relationships between headers and cells.

This guide explains the elements that make up a proper HTML table, what each one does for accessibility, how to style tables so they stay readable on small screens, and how to turn spreadsheet data into clean table code quickly.

The anatomy of an HTML table

A well-structured data table looks like this:

<table>
  <caption>Support plans</caption>
  <thead>
    <tr>
      <th scope="col">Plan</th>
      <th scope="col">Response time</th>
      <th scope="col">Price per month</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Standard</td>
      <td>1 business day</td>
      <td>$0</td>
    </tr>
    <tr>
      <td>Priority</td>
      <td>4 hours</td>
      <td>$49</td>
    </tr>
  </tbody>
</table>

What each part does:

  • <table> declares tabular data. Assistive technology announces the table and its size, and offers table navigation commands.
  • <caption> is the table's title. It is read first, so a screen reader user knows what the table is about before hearing any cells.
  • <thead>, <tbody> (and optionally <tfoot>) group the header rows and data rows. Browsers can repeat the header when a long table is printed across pages.
  • <th> marks a header cell. scope="col" says it labels a column; scope="row" labels a row. When a screen reader user moves to a cell, it announces the relevant header, such as "Response time, 4 hours".
  • <td> is an ordinary data cell.

Tables for data, not layout

Tables were once used for whole page layouts. That is now considered bad practice on the web because it confuses assistive technology and makes responsive design hard. Use CSS grid or flexbox for layout, and tables only for data that genuinely has rows and columns. (HTML email is the exception, where layout tables remain common; mark them with role="presentation".)

Build a table with the HTML Table Generator

Our HTML Table Generator lets you edit a grid visually and writes the table code for you.

  1. Open the HTML Table Generator. A sample pricing table is loaded.
  2. Edit cells directly in the grid. Use Add row and Add column to grow it (up to 200 rows and 20 columns), the remove buttons on each row and column to shrink it, and Clear cells to empty everything while keeping the size.
  3. To bring in existing data, click Paste from spreadsheet, paste cells copied from Excel, Google Sheets or Numbers (CSV text also works), and click Replace table with pasted data.
  4. Set the options:
    • First row is header puts the first row in <thead> with <th scope="col"> cells.
    • Include basic CSS adds a small stylesheet with borders and padding using the class data-table.
    • Striped rows and Row hover colour add zebra striping and a hover highlight (they switch basic CSS on automatically).
  5. Type a Caption (optional, helps accessibility), such as "Pricing plans".
  6. Check the Preview, then copy the HTML code or download it as table.html.

Special characters such as < and & in cells are escaped automatically, and line breaks inside a cell become <br>.

Making tables work on phones

A table with five or more columns rarely fits a 375-pixel screen. There are three honest options.

Let it scroll horizontally

Wrap the table in a container that scrolls, so the page itself does not:

<div class="table-scroll" role="region" aria-label="Support plans" tabindex="0">
  <table>…</table>
</div>
.table-scroll {
  overflow-x: auto;
}

The tabindex="0" lets keyboard users scroll the region, and the label tells screen reader users what it contains. This keeps the table's structure intact and is usually the best choice.

Reduce the columns

Ask whether every column is needed on every page. Two focused tables are often clearer than one wide one.

Restack into cards

With CSS you can display each row as a block on small screens. This can work for simple tables, but changing the display value of table elements can remove their table semantics in some browsers, so test with a screen reader if you choose it.

Check the result at phone width with the Responsive Design Tester once your page is online.

Other ways to create HTML tables

Export from a spreadsheet

Excel and Google Sheets can save or publish a sheet as a web page. The output works but usually contains a lot of inline styling and extra markup you would need to clean up.

Your CMS table block

Most content management systems have a table block. It is the easiest option for content editors, although some produce tables without header cells or captions. Check the output in your browser's inspector.

Markdown

If your platform renders Markdown, a pipe table is easier to maintain than HTML. The Markdown Table Generator builds one with column alignment.

Viewing large datasets

For hundreds of rows, a web page table is rarely the best reading experience. Offer a download, or let people explore the file in the CSV and Excel Viewer.

Tips and pitfalls

Right-align numbers

Numbers are easier to compare when their digits line up. Add text-align: right to numeric columns, and keep units in the header ("Price per month (USD)") rather than in every cell.

Avoid merged cells when you can

colspan and rowspan make tables harder to navigate for screen reader users and harder to make responsive. Split complex tables into simpler ones where possible.

Do not use empty cells for spacing

Use CSS padding. Empty cells are announced as "blank" by screen readers.

Keep the code tidy

If you edit the generated code by hand, run it through the HTML Formatter to keep indentation consistent.

Frequently asked questions

What is the difference between th and td?

<th> is a header cell that labels a row or column, and <td> is a data cell. Screen readers use the headers to announce context when moving between cells.

Do I need thead and tbody?

They are not required for a table to display, but they make the structure explicit, help with styling and printing, and are good practice for data tables.

What does the caption element do?

It gives the table a visible title that is programmatically linked to it, so screen readers announce it when the user reaches the table.

How do I copy a table from Excel into HTML?

Copy the cells in Excel, choose Paste from spreadsheet in the generator, paste, and click Replace table with pasted data. The tool writes the HTML for you.

How can I make a wide table readable on mobile?

Wrap it in a horizontally scrollable container with a label, or reduce the number of columns. Avoid shrinking the text until it becomes unreadable.

Try it now: HTML Table Generator

Loading tool…