Skip to the main content

Responsive Data Table

Free Data Display

A table with caption, scoped headers and right-aligned numbers that reflows into labelled stacked cards on a phone, in plain CSS.

Checked on 3 December 2026 in Chrome 143.0.7499.169: 12 automated checks. What the checks are

Preview and code

HTML

<section class="rdt" aria-labelledby="rdt-title">
  <h2 id="rdt-title" class="rdt__heading">Responsive data table</h2>
  <p class="rdt__lead">Wide on a desktop. On a phone each row turns into a labelled card. Example data.</p>
  <table class="rdt__table">
    <caption class="rdt__caption">Example project tasks and hours</caption>
    <thead>
      <tr><th scope="col">Task</th><th scope="col">Team</th><th scope="col" class="rdt__num">Hours</th><th scope="col">Status</th></tr>
    </thead>
    <tbody>
      <tr><th scope="row" data-label="Task">Wireframes</th><td data-label="Team">Design</td><td data-label="Hours" class="rdt__num">14</td><td data-label="Status"><span class="rdt__badge rdt__badge--done">Done</span></td></tr>
      <tr><th scope="row" data-label="Task">Colour tokens</th><td data-label="Team">Design</td><td data-label="Hours" class="rdt__num">9</td><td data-label="Status"><span class="rdt__badge rdt__badge--done">Done</span></td></tr>
      <tr><th scope="row" data-label="Task">Header and footer</th><td data-label="Team">Build</td><td data-label="Hours" class="rdt__num">22</td><td data-label="Status"><span class="rdt__badge rdt__badge--review">In review</span></td></tr>
      <tr><th scope="row" data-label="Task">Contact form</th><td data-label="Team">Build</td><td data-label="Hours" class="rdt__num">18</td><td data-label="Status"><span class="rdt__badge rdt__badge--progress">In progress</span></td></tr>
      <tr><th scope="row" data-label="Task">Keyboard pass</th><td data-label="Team">Review</td><td data-label="Hours" class="rdt__num">11</td><td data-label="Status"><span class="rdt__badge rdt__badge--progress">In progress</span></td></tr>
      <tr><th scope="row" data-label="Task">Release notes</th><td data-label="Team">Writing</td><td data-label="Hours" class="rdt__num">6</td><td data-label="Status"><span class="rdt__badge rdt__badge--todo">Not started</span></td></tr>
    </tbody>
    <tfoot>
      <tr><th scope="row" data-label="Total" colspan="2">Total hours</th><td data-label="Hours" class="rdt__num">80</td><td></td></tr>
    </tfoot>
  </table>
</section>

CSS

.rdt {
  --rdt-surface: #ffffff;
  --rdt-fg: #1b2032;
  --rdt-muted: #4a5266;
  --rdt-line: #d3d8e6;
  --rdt-head: #eceeff;
  --rdt-zebra: #f7f8fd;
  --rdt-accent: #4338ca;
  --rdt-done-bg: #dcf5e8; --rdt-done-fg: #0b5a34;
  --rdt-review-bg: #e9eaff; --rdt-review-fg: #3730a3;
  --rdt-progress-bg: #fdf0cf; --rdt-progress-fg: #7a4a00;
  --rdt-todo-bg: #eceef4; --rdt-todo-fg: #3d445a;
  box-sizing: border-box;
  width: min(100%, 44rem);
  color: var(--rdt-fg);
}
.rdt *, .rdt *::before, .rdt *::after { box-sizing: border-box; }
.rdt__heading { margin: 0; font-size: 1.25rem; letter-spacing: -0.01em; }
.rdt__lead { margin: 0.3rem 0 1rem; color: var(--rdt-muted); font-size: 0.9375rem; line-height: 1.5; }
.rdt__table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  background: var(--rdt-surface);
  border: 1px solid var(--rdt-line);
  border-radius: 14px;
  box-shadow: 0 6px 18px -14px rgba(27, 32, 50, 0.5);
}
.rdt__caption { padding: 0.85rem 1rem; color: var(--rdt-fg); font-size: 1rem; font-weight: 700; text-align: left; caption-side: top; background: var(--rdt-surface); }
.rdt__table th, .rdt__table td { padding: 0.8rem 1rem; text-align: left; border-top: 1px solid var(--rdt-line); }
.rdt__table thead th { color: var(--rdt-muted); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; background: var(--rdt-head); border-top: 0; }
.rdt__table tbody th { font-weight: 600; }
.rdt__table tbody tr:nth-child(even) > * { background: var(--rdt-zebra); }
.rdt__table tbody tr:hover > * { background: var(--rdt-head); }
.rdt__table tfoot th, .rdt__table tfoot td { font-weight: 700; background: var(--rdt-head); border-top: 2px solid var(--rdt-line); }
.rdt__table .rdt__num { text-align: right; font-variant-numeric: tabular-nums; }
.rdt__badge { display: inline-block; padding: 0.15rem 0.65rem; font-size: 0.8125rem; font-weight: 600; white-space: nowrap; border-radius: 999px; }
.rdt__badge::before { content: ""; display: inline-block; width: 0.5rem; height: 0.5rem; margin-right: 0.4rem; background: currentColor; border-radius: 50%; }
.rdt__badge--done { color: var(--rdt-done-fg); background: var(--rdt-done-bg); }
.rdt__badge--review { color: var(--rdt-review-fg); background: var(--rdt-review-bg); }
.rdt__badge--progress { color: var(--rdt-progress-fg); background: var(--rdt-progress-bg); }
.rdt__badge--todo { color: var(--rdt-todo-fg); background: var(--rdt-todo-bg); }

@media (max-width: 40em) {
  .rdt__table, .rdt__table tbody, .rdt__table tfoot, .rdt__table tr, .rdt__table th, .rdt__table td { display: block; }
  .rdt__table { background: transparent; border: 0; border-radius: 0; box-shadow: none; overflow: visible; }
  .rdt__table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .rdt__table tbody tr, .rdt__table tfoot tr { margin: 0 0 0.75rem; overflow: hidden; background: var(--rdt-surface); border: 1px solid var(--rdt-line); border-radius: 14px; }
  .rdt__table tbody tr:nth-child(even) > *, .rdt__table tbody tr:hover > * { background: transparent; }
  .rdt__table th, .rdt__table td, .rdt__table tfoot th, .rdt__table tfoot td { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.6rem 1rem; text-align: right; border-top: 1px solid var(--rdt-line); background: transparent; }
  .rdt__table tbody th, .rdt__table tfoot th { padding-top: 0.75rem; padding-bottom: 0.75rem; font-size: 1rem; text-align: left; background: var(--rdt-head); border-top: 0; }
  .rdt__table tbody th::before, .rdt__table tfoot th::before { content: none; }
  .rdt__table td::before { content: attr(data-label); color: var(--rdt-muted); font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; text-align: left; }
  .rdt__table tfoot tr { background: var(--rdt-head); }
  .rdt__table tfoot td:empty { display: none; }
  .rdt__table .rdt__num { text-align: right; }
  .rdt__caption { display: block; padding: 0 0 0.6rem; background: transparent; }
}
@media (prefers-color-scheme: dark) {
  .rdt {
    --rdt-surface: #1a1e2e;
    --rdt-fg: #edf0fa;
    --rdt-muted: #b9bfd3;
    --rdt-line: #3a4157;
    --rdt-head: #262b46;
    --rdt-zebra: #1e2335;
    --rdt-accent: #aeb1ff;
    --rdt-done-bg: #123b28; --rdt-done-fg: #8ef0bd;
    --rdt-review-bg: #2b2f5a; --rdt-review-fg: #c9cbff;
    --rdt-progress-bg: #4a3a10; --rdt-progress-fg: #ffd98a;
    --rdt-todo-bg: #2a2f44; --rdt-todo-fg: #c9cfe4;
  }
  .rdt__table { box-shadow: none; }
}

Accessibility notes

Written by the author of the snippet. Each note has a test step or a markup check that reads the page.

  • The table has a caption, header cells with scope, and a total row in tfoot.
  • Row headers use th with scope=row, so a cell is read with its row and column.
  • Status is written in words as well as colour.
Data Display
Free

Feature Icon

Beautiful icon containers for features

  • HTML
  • CSS
  • Tailwind
  • Font Awesome
Data Display