React Table Components With Tailwind and Plain HTML

Updated 2026-10-28. 5 tables.

You can build a React table without a library: keep the rows in an array, derive the sorted, filtered and paged rows with useMemo, and render a real table element with th scope and a caption. The five tables here do that, each in under two hundred lines, with a plain HTML version too.

Pick the table by the task people do with it. The sortable table is for scanning and ranking, such as orders by value. Row selection with a bulk action bar suits inboxes and admin lists, where people act on many rows at once. The paginated table with a search box suits long directories that would otherwise scroll forever.

The responsive table answers the hardest question about tables: phones. Below a set width each row turns into a card, with labels drawn from data attributes, while the markup stays a true table. The striped comparison table keeps its header stuck to the top of a scrolling box, which helps when people compare plans or specs down a long list.

All five are plain React with Tailwind classes. Reach for a headless table library only when you need column resizing, virtual scrolling of thousands of rows or server-side sorting; for everyday admin screens the code here is easier to read and change.

Compare them

VariantBuilt withSize (gzipped)Running costBrowser support
Sortable React Table With aria-sortCSS and a small script1.8 KBOne sort of a small array per click, memoised so other renders skip it.All current browsers
Paginated Table With Search FilterCSS and a small script2.6 KBFiltering eighteen rows per keystroke is trivial; only five rows render at once.All current browsers
Responsive Table That Becomes Cards on PhonesCSS only1.3 KBPure CSS: one media query restyles the same table, with no script or resize listener.All current browsers
Striped Comparison Table With Sticky HeaderCSS only1.4 KBSticky positioning is handled by the browser while scrolling, with no scroll listener.All current browsers
Table With Row Selection and Bulk ActionsCSS and a small script1.8 KBSelection is a Set of ids, so ticking a row is constant time at any length.All current browsers

Sortable React Table With aria-sort

A recent orders table for a small candle shop. Every column heading is a button; clicking sorts by that column and clicking again flips the order, with a two-way arrow that darkens on the active side. The sorted column carries aria-sort, the table has a real caption and each order number is a row header. On phones the card scrolls sideways instead of squashing columns.

<section class="srt">
  <div class="srt-card">
    <table>
      <caption><strong>Recent orders</strong><span>Wren &amp; Thistle Candles. Click a column heading to sort.</span></caption>
      <thead>
        <tr>
          <th scope="col"><button type="button" data-key="0">Order<i aria-hidden="true"></i></button></th>
          <th scope="col"><button type="button" data-key="1">Customer<i aria-hidden="true"></i></button></th>
          <th scope="col"><button type="button" data-key="2">City<i aria-hidden="true"></i></button></th>
          <th scope="col" aria-sort="descending"><button type="button" data-key="3">Date<i aria-hidden="true"></i></button></th>
          <th scope="col" class="srt-num"><button type="button" data-key="4" data-type="number">Total<i aria-hidden="true"></i></button></th>
          <th scope="col"><button type="button" data-key="5">Status<i aria-hidden="true"></i></button></th>
        </tr>
      </thead>
      <tbody>
        <tr><th scope="row">#4821</th><td>Hana Osei</td><td>Leeds</td><td data-sort="2026-10-24">24 Oct</td><td class="srt-num" data-sort="184.5">£184.50</td><td><span class="srt-b srt-paid">Paid</span></td></tr>
        <tr><th scope="row">#4820</th><td>Mateo Ruiz</td><td>Bristol</td><td data-sort="2026-10-23">23 Oct</td><td class="srt-num" data-sort="62">£62.00</td><td><span class="srt-b srt-pending">Pending</span></td></tr>
        <tr><th scope="row">#4819</th><td>Clara Vos</td><td>York</td><td data-sort="2026-10-23">23 Oct</td><td class="srt-num" data-sort="311.2">£311.20</td><td><span class="srt-b srt-paid">Paid</span></td></tr>
        <tr><th scope="row">#4818</th><td>Idris Bello</td><td>Cardiff</td><td data-sort="2026-10-21">21 Oct</td><td class="srt-num" data-sort="47.9">£47.90</td><td><span class="srt-b">Refunded</span></td></tr>
        <tr><th scope="row">#4817</th><td>Nell Park</td><td>Glasgow</td><td data-sort="2026-10-20">20 Oct</td><td class="srt-num" data-sort="129">£129.00</td><td><span class="srt-b srt-paid">Paid</span></td></tr>
        <tr><th scope="row">#4816</th><td>Arjun Mehta</td><td>Brighton</td><td data-sort="2026-10-18">18 Oct</td><td class="srt-num" data-sort="238.75">£238.75</td><td><span class="srt-b srt-pending">Pending</span></td></tr>
      </tbody>
    </table>
  </div>
</section>
<style>
  /* Change these: accent for the sorted arrow and focus ring, row line colour. */
  .srt { --srt-accent: #4f46e5; --srt-line: #f1f5f9; }
  .srt { background: #f8fafc; padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; color: #0f172a; }
  .srt-card { max-width: 56rem; margin: 0 auto; overflow-x: auto; background: #fff; border: 1px solid #e2e8f0; border-radius: 16px; box-shadow: 0 1px 2px rgba(15,23,42,.05); }
  .srt table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 14px; text-align: left; }
  .srt caption { padding: 20px 20px 12px; text-align: left; }
  .srt caption strong { display: block; font-size: 18px; }
  .srt caption span { display: block; font-size: 14px; color: #475569; }
  .srt thead tr { background: #f8fafc; border-top: 1px solid #e2e8f0; border-bottom: 1px solid #e2e8f0; }
  .srt thead th { padding: 4px 8px; font-weight: 500; }
  .srt thead button { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: #475569; font: inherit; cursor: pointer; }
  .srt thead button:hover { background: #e2e8f0; color: #0f172a; }
  .srt thead button:focus-visible { outline: 2px solid var(--srt-accent); outline-offset: 1px; }
  /* Arrow: both triangles when unsorted, one when sorted. */
  .srt thead i { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid #94a3b8; }
  .srt th[aria-sort] button { color: #0f172a; }
  .srt th[aria-sort="ascending"] i { border-top: 0; border-bottom: 5px solid var(--srt-accent); }
  .srt th[aria-sort="descending"] i { border-top-color: var(--srt-accent); }
  .srt .srt-num { text-align: right; }
  .srt .srt-num button { flex-direction: row-reverse; }
  .srt tbody tr { border-bottom: 1px solid var(--srt-line); }
  .srt tbody tr:last-child { border-bottom: 0; }
  .srt tbody tr:hover { background: #f8fafc; }
  .srt tbody th, .srt tbody td { padding: 14px 20px; color: #334155; }
  .srt tbody th { font-weight: 500; color: #0f172a; }
  .srt td.srt-num { font-weight: 500; color: #0f172a; font-variant-numeric: tabular-nums; }
  .srt-b { padding: 4px 10px; border-radius: 99px; background: #f1f5f9; color: #334155; font-size: 12px; font-weight: 500; }
  .srt-paid { background: #ecfdf5; color: #065f46; }
  .srt-pending { background: #fffbeb; color: #92400e; }
</style>
<script>
  (function () {
    var root = document.querySelector(".srt");
    if (!root) return;
    var tbody = root.querySelector("tbody");
    var ths = root.querySelectorAll("thead th");
    ths.forEach(function (th) {
      var btn = th.querySelector("button");
      btn.addEventListener("click", function () {
        var col = Number(btn.dataset.key), num = btn.dataset.type === "number";
        var dir = th.getAttribute("aria-sort") === "ascending" ? "descending" : "ascending";
        ths.forEach(function (h) { h.removeAttribute("aria-sort"); });
        th.setAttribute("aria-sort", dir);
        var rows = Array.prototype.slice.call(tbody.rows);
        rows.sort(function (a, b) {
          var x = a.cells[col].dataset.sort || a.cells[col].textContent, y = b.cells[col].dataset.sort || b.cells[col].textContent;
          var r = num ? Number(x) - Number(y) : x.localeCompare(y);
          return dir === "ascending" ? r : -r;
        });
        rows.forEach(function (r) { tbody.appendChild(r); });
      });
    });
  })();
</script>

With reduced motion: Rows reorder instantly; there is no motion to turn off.

Running cost: One sort of a small array per click, memoised so other renders skip it.

  • Add or remove a column by editing the columns array; set numeric: true to right-align it and put the arrow before the label.
  • Change the starting order in useState, for example { key: "total", dir: "descending" } to show the biggest orders first.
  • Swap the badge map colours for your own statuses; each entry is a background, text and ring class trio.
  • In the HTML version, put the raw value in data-sort on any cell whose displayed text would sort wrongly, such as dates or prices.

Full page for Sortable React Table With aria-sort

Paginated Table With Search Filter

A stock list for a plant nursery with a search box that filters by name or type as you type and numbered pages of five rows below. Typing always returns you to page one, the count line reads like 6 to 10 of 18 plants, and sold-out lines are flagged in red text. The search field drops under the heading on phones while the table scrolls sideways.

<section class="tpg">
  <div class="tpg-card">
    <div class="tpg-head">
      <h2>Greenhythe Nursery stock</h2>
      <div class="tpg-search">
        <label for="tpg-q" class="tpg-sr">Search plants</label>
        <svg viewBox="0 0 20 20" aria-hidden="true"><circle cx="9" cy="9" r="6"/><path d="m14 14 4 4"/></svg>
        <input id="tpg-q" type="search" placeholder="Search by name or type">
      </div>
    </div>
    <div class="tpg-scroll">
      <table>
        <caption class="tpg-sr">Plants in stock</caption>
        <thead><tr><th scope="col">Plant</th><th scope="col">Type</th><th scope="col">Pot</th><th scope="col" class="tpg-num">Price</th><th scope="col" class="tpg-num">In stock</th></tr></thead>
        <tbody>
          <tr><th scope="row">Japanese maple &#39;Bloodgood&#39;</th><td>Tree</td><td>10 L</td><td class="tpg-num">£89.00</td><td class="tpg-num">6</td></tr>
          <tr><th scope="row">Lavender &#39;Hidcote&#39;</th><td>Shrub</td><td>2 L</td><td class="tpg-num">£9.50</td><td class="tpg-num">48</td></tr>
          <tr><th scope="row">Hellebore &#39;Ivory Prince&#39;</th><td>Perennial</td><td>3 L</td><td class="tpg-num">£14.00</td><td class="tpg-num">22</td></tr>
          <tr><th scope="row">Silver birch</th><td>Tree</td><td>15 L</td><td class="tpg-num">£65.00</td><td class="tpg-num">9</td></tr>
          <tr><th scope="row">Hydrangea &#39;Annabelle&#39;</th><td>Shrub</td><td>5 L</td><td class="tpg-num">£24.00</td><td class="tpg-num">15</td></tr>
          <tr><th scope="row">Foxglove &#39;Pam&#39;s Choice&#39;</th><td>Perennial</td><td>2 L</td><td class="tpg-num">£8.00</td><td class="tpg-num tpg-out">Sold out</td></tr>
          <tr><th scope="row">Box ball 30 cm</th><td>Topiary</td><td>7 L</td><td class="tpg-num">£39.00</td><td class="tpg-num">12</td></tr>
          <tr><th scope="row">Rosemary &#39;Miss Jessopp&#39;</th><td>Herb</td><td>1 L</td><td class="tpg-num">£6.50</td><td class="tpg-num">60</td></tr>
          <tr><th scope="row">Crab apple &#39;Red Sentinel&#39;</th><td>Tree</td><td>12 L</td><td class="tpg-num">£75.00</td><td class="tpg-num">4</td></tr>
          <tr><th scope="row">Salvia &#39;Caradonna&#39;</th><td>Perennial</td><td>2 L</td><td class="tpg-num">£9.00</td><td class="tpg-num">31</td></tr>
          <tr><th scope="row">Pittosporum &#39;Tom Thumb&#39;</th><td>Shrub</td><td>3 L</td><td class="tpg-num">£18.00</td><td class="tpg-num">11</td></tr>
          <tr><th scope="row">Thyme &#39;Silver Posie&#39;</th><td>Herb</td><td>9 cm</td><td class="tpg-num">£4.00</td><td class="tpg-num">75</td></tr>
          <tr><th scope="row">Bay tree standard</th><td>Topiary</td><td>20 L</td><td class="tpg-num">£120.00</td><td class="tpg-num">3</td></tr>
          <tr><th scope="row">Geranium &#39;Rozanne&#39;</th><td>Perennial</td><td>2 L</td><td class="tpg-num">£10.00</td><td class="tpg-num">40</td></tr>
          <tr><th scope="row">Olive tree</th><td>Tree</td><td>25 L</td><td class="tpg-num">£149.00</td><td class="tpg-num">2</td></tr>
          <tr><th scope="row">Mint &#39;Moroccan&#39;</th><td>Herb</td><td>1 L</td><td class="tpg-num">£5.00</td><td class="tpg-num tpg-out">Sold out</td></tr>
          <tr><th scope="row">Viburnum tinus</th><td>Shrub</td><td>5 L</td><td class="tpg-num">£22.00</td><td class="tpg-num">19</td></tr>
          <tr><th scope="row">Agapanthus &#39;Navy Blue&#39;</th><td>Perennial</td><td>3 L</td><td class="tpg-num">£16.00</td><td class="tpg-num">27</td></tr>
        </tbody>
      </table>
      <p class="tpg-empty" hidden>No plants match that search.</p>
    </div>
    <nav class="tpg-nav" aria-label="Table pages">
      <p aria-live="polite"></p>
      <div class="tpg-pages"></div>
    </nav>
  </div>
</section>
<style>
  /* Change these: accent, rows per page is set in the script (PER_PAGE). */
  .tpg { --tpg-accent: #0369a1; }
  .tpg { background: #f0f9ff; padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; color: #0f172a; }
  .tpg-card { max-width: 56rem; margin: 0 auto; padding: 24px; background: #fff; border: 1px solid #e0f2fe; border-radius: 16px; box-shadow: 0 1px 2px rgba(15,23,42,.05); }
  .tpg-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
  .tpg-head h2 { margin: 0; font-size: 18px; }
  .tpg-search { position: relative; width: 100%; max-width: 288px; }
  .tpg-search svg { position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: none; stroke: #64748b; stroke-width: 2; stroke-linecap: round; }
  .tpg-search input { box-sizing: border-box; width: 100%; height: 40px; padding: 0 12px 0 36px; border: 1px solid #cbd5e1; border-radius: 8px; font: 14px ui-sans-serif, system-ui, sans-serif; }
  .tpg-search input:focus { outline: 2px solid var(--tpg-accent); outline-offset: 1px; }
  .tpg-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .tpg-scroll { margin-top: 20px; overflow-x: auto; }
  .tpg table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 14px; text-align: left; }
  .tpg thead th { padding: 10px 12px; border-bottom: 1px solid #e2e8f0; font-weight: 500; color: #475569; }
  .tpg tbody tr { border-bottom: 1px solid #f1f5f9; }
  .tpg tbody th, .tpg tbody td { padding: 12px; color: #475569; }
  .tpg tbody th { font-weight: 500; color: #0f172a; }
  .tpg th:first-child { padding-left: 0; }
  .tpg th:last-child, .tpg td:last-child { padding-right: 0; }
  .tpg .tpg-num { text-align: right; font-variant-numeric: tabular-nums; }
  .tpg .tpg-out { color: #be123c; font-weight: 500; }
  .tpg-empty { margin: 0; padding: 40px 0; text-align: center; font-size: 14px; color: #475569; }
  .tpg-nav { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 16px; border-top: 1px solid #f1f5f9; }
  .tpg-nav p { margin: 0; font-size: 14px; color: #475569; }
  .tpg-pages { display: flex; gap: 4px; }
  .tpg-pages button { min-width: 40px; height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: none; color: #334155; font: 500 14px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
  .tpg-pages button:hover { background: #f1f5f9; }
  .tpg-pages button[aria-current] { background: var(--tpg-accent); color: #fff; }
  .tpg-pages button:disabled { opacity: .4; cursor: default; }
  .tpg-pages button:focus-visible { outline: 2px solid var(--tpg-accent); outline-offset: 1px; }
</style>
<script>
  (function () {
    var root = document.querySelector(".tpg");
    if (!root) return;
    var PER_PAGE = 5, page = 1;
    var rows = Array.prototype.slice.call(root.querySelectorAll("tbody tr"));
    var input = root.querySelector("input"), info = root.querySelector(".tpg-nav p"), pager = root.querySelector(".tpg-pages"), empty = root.querySelector(".tpg-empty");
    function btn(label, target, opts) {
      var b = document.createElement("button");
      b.type = "button"; b.textContent = label;
      if (opts.current) b.setAttribute("aria-current", "page");
      if (opts.aria) b.setAttribute("aria-label", opts.aria);
      b.disabled = !!opts.disabled;
      b.addEventListener("click", function () { page = target; render(); });
      return b;
    }
    function render() {
      var q = input.value.trim().toLowerCase();
      var found = rows.filter(function (r) { return (r.cells[0].textContent + " " + r.cells[1].textContent).toLowerCase().indexOf(q) > -1; });
      var pages = Math.max(1, Math.ceil(found.length / PER_PAGE));
      page = Math.min(page, pages);
      rows.forEach(function (r) { r.hidden = true; });
      found.slice((page - 1) * PER_PAGE, page * PER_PAGE).forEach(function (r) { r.hidden = false; });
      empty.hidden = found.length > 0;
      var first = found.length ? (page - 1) * PER_PAGE + 1 : 0;
      info.textContent = first + " to " + Math.min(page * PER_PAGE, found.length) + " of " + found.length + " plants";
      pager.replaceChildren();
      pager.appendChild(btn("Previous", page - 1, { disabled: page === 1 }));
      for (var n = 1; n <= pages; n++) pager.appendChild(btn(String(n), n, { current: n === page, aria: "Page " + n }));
      pager.appendChild(btn("Next", page + 1, { disabled: page === pages }));
    }
    input.addEventListener("input", function () { page = 1; render(); });
    render();
  })();
</script>

With reduced motion: Pages change in place with no transition to switch off.

Running cost: Filtering eighteen rows per keystroke is trivial; only five rows render at once.

  • Change PER_PAGE to show more rows per page; ten to twenty-five suits most admin screens.
  • Search more fields by adding them to the template string inside the filter, for example the pot size.
  • Replace sky-700 on the current page button and the focus rings to match your brand colour.

Responsive Table That Becomes Cards on Phones

A weekly class timetable for a climbing gym that reads as a normal ruled table on wider screens and turns each row into a white card below 640 pixels. The column names come back on phones through data-label attributes shown with ::before, so every value keeps its label. Spaces are colour-coded pills: plenty, nearly gone, or full.

<section class="trc">
  <table>
    <caption><strong>This week at Crux Wall</strong><span>Book at the desk or in the app. Spaces update every hour.</span></caption>
    <thead>
      <tr><th scope="col">Class</th><th scope="col">Coach</th><th scope="col">When</th><th scope="col">Level</th><th scope="col" class="trc-num">Spaces</th></tr>
    </thead>
    <tbody>
        <tr><th scope="row">Intro to bouldering</th><td data-label="Coach">Ayla Brennan</td><td data-label="When">Mon 18:30</td><td data-label="Level">Beginner</td><td data-label="Spaces" class="trc-num"><span class="trc-b">4 left</span></td></tr>
        <tr><th scope="row">Lead climbing skills</th><td data-label="Coach">Dev Sharma</td><td data-label="When">Tue 19:00</td><td data-label="Level">Intermediate</td><td data-label="Spaces" class="trc-num"><span class="trc-b trc-full">Full</span></td></tr>
        <tr><th scope="row">Youth squad</th><td data-label="Coach">Marta Kowal</td><td data-label="When">Wed 16:30</td><td data-label="Level">Ages 10 to 15</td><td data-label="Spaces" class="trc-num"><span class="trc-b">7 left</span></td></tr>
        <tr><th scope="row">Technique clinic</th><td data-label="Coach">Ayla Brennan</td><td data-label="When">Thu 18:00</td><td data-label="Level">All levels</td><td data-label="Spaces" class="trc-num"><span class="trc-b trc-low">2 left</span></td></tr>
        <tr><th scope="row">Sunday social climb</th><td data-label="Coach">Leo Hart</td><td data-label="When">Sun 10:00</td><td data-label="Level">All levels</td><td data-label="Spaces" class="trc-num"><span class="trc-b">12 left</span></td></tr>
    </tbody>
  </table>
</section>
<style>
  /* Change these: page colour, card colour, the width where rows turn into cards (in the media query). */
  .trc { --trc-bg: #fffbeb; --trc-card: #fff; --trc-rule: #fde68a; }
  .trc { background: var(--trc-bg); padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; color: #1c1917; }
  .trc table { width: 100%; max-width: 56rem; margin: 0 auto; border-collapse: collapse; font-size: 14px; text-align: left; }
  .trc caption { padding-bottom: 20px; text-align: left; }
  .trc caption strong { display: block; font-size: 24px; letter-spacing: -.02em; }
  .trc caption span { display: block; margin-top: 4px; font-size: 15px; color: #57534e; }
  .trc thead tr { border-bottom: 2px solid #1c1917; }
  .trc th, .trc td { padding: 14px 16px; }
  .trc thead th { font-weight: 600; }
  .trc tbody tr { border-bottom: 1px solid var(--trc-rule); }
  .trc tbody th { font-weight: 600; }
  .trc td { color: #44403c; }
  .trc .trc-num { text-align: right; }
  .trc-b { padding: 4px 10px; border-radius: 99px; background: #d9f99d; color: #365314; font-size: 12px; font-weight: 600; }
  .trc-low { background: #fde68a; color: #78350f; }
  .trc-full { background: #e7e5e4; color: #44403c; }
  /* Phones: every row is a card; each cell shows its column name from data-label. */
  @media (max-width: 639px) {
    .trc table, .trc caption, .trc tbody, .trc tr, .trc th, .trc td { display: block; }
    .trc thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .trc tbody tr { margin-bottom: 12px; padding: 16px; border: 1px solid var(--trc-rule); border-radius: 16px; background: var(--trc-card); box-shadow: 0 1px 2px rgba(0,0,0,.05); }
    .trc tbody th { padding: 0 0 8px; font-size: 16px; }
    .trc td { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 6px 0; }
    .trc td::before { content: attr(data-label); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: #78716c; }
  }
</style>

With reduced motion: Static by design; the switch to cards happens only at the breakpoint.

Running cost: Pure CSS: one media query restyles the same table, with no script or resize listener.

  • Move the switch point by changing max-sm: (or the 639px media query) to a wider breakpoint if your table has more columns.
  • Keep each data-label in step with its column heading; it is the only label people see on phones.
  • Adjust the thresholds in the spaces pill (0 for full, under 4 for low) to match how your bookings fill.

Striped Comparison Table With Sticky Header

A spec comparison for three e-bike models inside a box of fixed height. The dark header row with the model names stays pinned while you scroll down thirteen rows of range, weight and parts, and on phones the cells tighten and wrap so all three models fit side by side. Rows alternate with a pale teal stripe, ticks and dashes mark yes and no, and price closes the list in bold.

<section class="tcs">
  <div class="tcs-inner">
    <h2>Compare Velomarsh e-bikes</h2>
    <p class="tcs-sub">Scroll the table; the model names stay at the top.</p>
    <div class="tcs-box" tabindex="0" role="region" aria-label="E-bike comparison, scrollable">
      <table>
        <caption class="tcs-sr">Velomarsh e-bike models compared feature by feature</caption>
        <thead><tr><th scope="col">Feature</th><th scope="col">Commuter</th><th scope="col">Tourer</th><th scope="col">Cargo</th></tr></thead>
        <tbody>
          <tr><th scope="row">Range on one charge</th><td>60 km</td><td>110 km</td><td>85 km</td></tr>
          <tr><th scope="row">Motor</th><td>250 W hub</td><td>250 W mid-drive</td><td>250 W mid-drive</td></tr>
          <tr><th scope="row">Weight</th><td>19 kg</td><td>23 kg</td><td>34 kg</td></tr>
          <tr><th scope="row">Gears</th><td>Single speed</td><td>Belt hub, 8</td><td>Belt hub, 5</td></tr>
          <tr><th scope="row">Integrated lights</th><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td></tr>
          <tr><th scope="row">Rear rack</th><td><span class="tcs-no" aria-hidden="true"></span><span class="tcs-sr">Not included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td></tr>
          <tr><th scope="row">Front cargo box</th><td><span class="tcs-no" aria-hidden="true"></span><span class="tcs-sr">Not included</span></td><td><span class="tcs-no" aria-hidden="true"></span><span class="tcs-sr">Not included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td></tr>
          <tr><th scope="row">Suspension fork</th><td><span class="tcs-no" aria-hidden="true"></span><span class="tcs-sr">Not included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td><td><span class="tcs-no" aria-hidden="true"></span><span class="tcs-sr">Not included</span></td></tr>
          <tr><th scope="row">Hydraulic disc brakes</th><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td></tr>
          <tr><th scope="row">App lock and tracking</th><td><span class="tcs-no" aria-hidden="true"></span><span class="tcs-sr">Not included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td><td><span class="tcs-yes" aria-hidden="true"></span><span class="tcs-sr">Included</span></td></tr>
          <tr><th scope="row">Max rider and load</th><td>120 kg</td><td>130 kg</td><td>200 kg</td></tr>
          <tr><th scope="row">Warranty</th><td>2 years</td><td>3 years</td><td>3 years</td></tr>
          <tr><th scope="row">Price</th><td>£1,290</td><td>£2,450</td><td>£3,180</td></tr>
        </tbody>
      </table>
    </div>
  </div>
</section>
<style>
  /* Change these: header colour, stripe colour, box height. */
  .tcs { --tcs-head: #0f172a; --tcs-stripe: #f3faf9; --tcs-height: 420px; }
  .tcs { background: #fff; padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; color: #0f172a; }
  .tcs-inner { max-width: 56rem; margin: 0 auto; }
  .tcs h2 { margin: 0; font-size: clamp(24px, 3.4vw, 30px); letter-spacing: -.02em; }
  .tcs-sub { margin: 8px 0 0; font-size: 15px; color: #475569; }
  .tcs-box { margin-top: 32px; max-height: var(--tcs-height); overflow: auto; border: 1px solid #e2e8f0; border-radius: 12px; }
  .tcs-box:focus-visible { outline: 2px solid #0f766e; outline-offset: 2px; }
  /* border-collapse: separate keeps sticky cells' backgrounds clean while scrolling. */
  .tcs table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; text-align: left; }
  .tcs th, .tcs td { padding: 12px; } @media (min-width: 640px) { .tcs th, .tcs td { padding: 12px 16px; } }
  .tcs thead th { position: sticky; top: 0; z-index: 2; padding: 14px 16px; background: var(--tcs-head); color: #fff; font-size: 16px; font-weight: 600; }
  @media (max-width: 639px) { .tcs thead th { font-size: 14px; padding: 12px 8px; } .tcs th, .tcs td { padding: 10px 8px; } }
  .tcs thead th:first-child { left: 0; z-index: 3; color: #cbd5e1; font-size: 14px; font-weight: 500; }
  .tcs tbody th { position: sticky; left: 0; z-index: 1; font-weight: 500; background: #fff; }
  .tcs tbody td { color: #334155; }
  .tcs tbody tr:nth-child(odd), .tcs tbody tr:nth-child(odd) th { background: var(--tcs-stripe); }
  .tcs tbody tr:last-child td { font-weight: 600; color: #0f172a; }
  .tcs-yes { display: inline-block; width: 10px; height: 5px; border-left: 2px solid #115e59; border-bottom: 2px solid #115e59; transform: rotate(-45deg) translate(1px, -2px); }
  .tcs-no { display: inline-block; width: 12px; height: 2px; border-radius: 2px; background: #94a3b8; vertical-align: middle; }
  .tcs-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
</style>

With reduced motion: Nothing animates; scrolling is the only movement and it is the reader's own.

Running cost: Sticky positioning is handled by the browser while scrolling, with no scroll listener.

  • Change the box height with max-h-[420px] (or --tcs-height); remove it entirely to let the page scroll and keep the header sticky to the window.
  • Replace bg-teal-50/60 and the matching #f3faf9 on the sticky row headers together so the stripe stays even under the pinned column.
  • Add a model by adding a name to plans and one more value to every row array.

Table With Row Selection and Bulk Actions

A newsletter subscriber list for a bakery with a checkbox on every row and a select-all box in the header that turns indeterminate when only some rows are ticked. As soon as anything is selected, the bar above swaps its summary for a count and two actions; Archive really removes the chosen rows. Selected rows take a soft rose tint, and the table scrolls sideways on phones.

<section class="trs">
  <div class="trs-card">
    <div class="trs-bar" aria-live="polite">
      <p class="trs-idle">5 subscribers. Tick rows to act on them.</p>
      <p class="trs-count" hidden></p>
      <div class="trs-actions" hidden>
        <button type="button" class="trs-ghost">Export CSV</button>
        <button type="button" class="trs-archive">Archive</button>
      </div>
    </div>
    <div class="trs-scroll">
      <table>
        <caption>Newsletter subscribers for The Saturday Loaf</caption>
        <thead>
          <tr><th scope="col"><input type="checkbox" class="trs-all" aria-label="Select all subscribers"></th><th scope="col">Name</th><th scope="col">Email</th><th scope="col">Plan</th><th scope="col">Joined</th></tr>
        </thead>
        <tbody>
          <tr><td><input type="checkbox" aria-label="Select Priya Natarajan"></td><th scope="row">Priya Natarajan</th><td>[email protected]</td><td>Annual</td><td>12 Mar 2026</td></tr>
          <tr><td><input type="checkbox" aria-label="Select Owen Gallagher"></td><th scope="row">Owen Gallagher</th><td>[email protected]</td><td>Monthly</td><td>2 Apr 2026</td></tr>
          <tr><td><input type="checkbox" aria-label="Select Sofia Lindqvist"></td><th scope="row">Sofia Lindqvist</th><td>[email protected]</td><td>Free</td><td>19 May 2026</td></tr>
          <tr><td><input type="checkbox" aria-label="Select Kwame Asante"></td><th scope="row">Kwame Asante</th><td>[email protected]</td><td>Annual</td><td>7 Jul 2026</td></tr>
          <tr><td><input type="checkbox" aria-label="Select Maud Fischer"></td><th scope="row">Maud Fischer</th><td>[email protected]</td><td>Monthly</td><td>30 Aug 2026</td></tr>
        </tbody>
      </table>
    </div>
  </div>
</section>
<style>
  /* Change these: accent for checkboxes and the main action, selected row tint. */
  .trs { --trs-accent: #be123c; --trs-tint: #fff1f2; }
  .trs { background: #fff8f8; padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; color: #0f172a; }
  .trs-card { max-width: 56rem; margin: 0 auto; overflow: hidden; background: #fff; border: 1px solid #ffe4e6; border-radius: 16px; box-shadow: 0 1px 2px rgba(15,23,42,.05); }
  .trs-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; padding: 12px 20px; box-sizing: border-box; }
  .trs-bar p { margin: 0; font-size: 14px; color: #475569; }
  .trs-count { font-weight: 500; color: #0f172a !important; }
  .trs-actions { display: flex; gap: 8px; }
  .trs-actions[hidden], .trs-bar p[hidden] { display: none; }
  .trs-bar button { height: 40px; padding: 0 14px; border-radius: 8px; font: 500 14px ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
  .trs-ghost { border: 1px solid #cbd5e1; background: #fff; color: #334155; }
  .trs-archive { border: 0; background: var(--trs-accent); color: #fff; }
  .trs button:focus-visible, .trs input:focus-visible { outline: 2px solid var(--trs-accent); outline-offset: 2px; }
  .trs-scroll { overflow-x: auto; }
  .trs table { width: 100%; min-width: 600px; border-collapse: collapse; font-size: 14px; text-align: left; }
  .trs caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .trs thead { background: #f8fafc; border-top: 1px solid #e2e8f0; border-bottom: 1px solid #e2e8f0; }
  .trs thead th { padding: 12px; font-weight: 500; color: #475569; }
  .trs th:first-child, .trs td:first-child { width: 48px; padding-left: 20px; }
  .trs tbody tr { border-bottom: 1px solid #f1f5f9; }
  .trs tbody th, .trs tbody td { padding: 14px 12px; color: #475569; }
  .trs tbody th { font-weight: 500; color: #0f172a; }
  .trs tbody tr.on { background: var(--trs-tint); }
  .trs input { width: 16px; height: 16px; accent-color: var(--trs-accent); }
</style>
<script>
  (function () {
    var root = document.querySelector(".trs");
    if (!root) return;
    var all = root.querySelector(".trs-all"), tbody = root.querySelector("tbody");
    var idle = root.querySelector(".trs-idle"), count = root.querySelector(".trs-count"), actions = root.querySelector(".trs-actions"), archive = root.querySelector(".trs-archive");
    function boxes() { return tbody.querySelectorAll("input"); }
    function update() {
      var list = boxes(), n = 0;
      list.forEach(function (b) { b.closest("tr").classList.toggle("on", b.checked); if (b.checked) n++; });
      all.checked = n > 0 && n === list.length;
      all.indeterminate = n > 0 && n < list.length;
      idle.hidden = n > 0; count.hidden = actions.hidden = n === 0;
      idle.textContent = list.length + " subscribers. Tick rows to act on them.";
      count.textContent = n + " selected";
      archive.textContent = "Archive " + n;
    }
    tbody.addEventListener("change", update);
    all.addEventListener("change", function () { boxes().forEach(function (b) { b.checked = all.checked; }); update(); });
    archive.addEventListener("click", function () {
      boxes().forEach(function (b) { if (b.checked) b.closest("tr").remove(); });
      update();
    });
    boxes()[1].checked = true; boxes()[3].checked = true;
    update();
  })();
</script>

With reduced motion: Nothing animates; the bar simply swaps its text and buttons.

Running cost: Selection is a Set of ids, so ticking a row is constant time at any length.

  • Replace Export CSV and Archive with your own actions; each receives the picked Set, so you know exactly which ids to send.
  • Change accent-rose-700 on the checkboxes and bg-rose-50 on selected rows to recolour selection in one go.
  • Start with nothing selected by seeding picked with new Set() instead of new Set([2, 4]).

Performance notes

Sorting and filtering a few hundred rows in the browser takes well under a millisecond, so these tables do it on every keystroke. useMemo keeps the work from repeating when unrelated state changes, and each row has a stable key so React updates only the cells that move.

Past a few thousand rows, rendering becomes the cost rather than sorting. Paginate as the third table does, or window the rows so only the visible ones are in the page. The sticky header uses position: sticky, which the browser handles while scrolling with no scroll listener.

Questions

Do I need a library to build a table in React?

No. Sorting, filtering, selection and paging are each a few lines over an array. A library starts to pay off with column resizing, grouping, virtualisation or large server-driven data sets.

How do I make table headers sortable and accessible?

Put a button inside each sortable th so it is reachable by keyboard, and set aria-sort to ascending or descending on the th that is currently sorted. Leave aria-sort off the other headers.

How do I make an HTML table responsive?

Either let it scroll sideways inside a wrapper with overflow-x: auto, or below a breakpoint display each row as a block and show the column name before each cell with a data-label attribute and ::before content.

How do I style a table with Tailwind?

Use w-full and border-collapse on the table, text-left and a small uppercase or medium weight on th, padding such as px-4 py-3 on cells, divide-y on tbody for row lines, and odd:bg-slate-50 for stripes.

How do I keep a table header visible while scrolling?

Give the th elements position: sticky and top: 0 with a solid background, and put the table inside a box with a fixed height and overflow: auto. Sticky works on th in every current browser.

Also in the gallery: Tailwind Table: React Data Table with Sorting, Search, Row Selection and Pagination, Sortable Order Table Beside a WebGL Oak Card Index Drawer That Riffles Its Cards into the New Order and Lifts the Hovered Row.

More collections: Accordion Components in Tailwind, HTML and CSS, Bento Grid Layouts in CSS and Tailwind, Horizontal Scroll Sections. All tables and lists. Build your site free to have a full site built around them.

Product

Who It's For

Features

Resources

Company

View Sitemap