Web development

Mark up a small data table

Use a table for data with meaningful row and column relationships. Add a caption and appropriate header cells so the relationships remain understandable beyond the visual grid.

Worked example

HTML example · save as example.html and open in a browser

<table>
  <caption>Example file sizes</caption>
  <thead><tr><th scope="col">File</th><th scope="col">Bytes</th></tr></thead>
  <tbody>
    <tr><th scope="row">notes.txt</th><td>120</td></tr>
    <tr><th scope="row">data.json</th><td>480</td></tr>
  </tbody>
</table>

How it works

The caption describes the table as a whole. Column and row headers identify what each numeric value means. A table can be placed inside a horizontally scrollable wrapper on narrow screens without discarding its semantic relationships.

Limits and mistakes

Tables are not a general page-layout mechanism. Complex merged headers require more careful associations than this simple example. Do not remove header semantics solely to make the mobile presentation resemble a list.

Check the result

Read a numeric cell using a screen reader’s table navigation and confirm its file and byte-count headings are available. Check the table at a narrow viewport without clipping values.

Sources

Reference documentation for the behavior used in this guide: