Table

A grid of facts people compare: a caption, sortable columns that say how they are sorted, and rows that turn into cards on a phone.

Try it

Press a column name to sort by it, and again to flip the order. Switch to Phone width to see each row become a card.

Clients, sorted by Client, ascending
Status
Copper Kettle CafeStarterPaused$19
Harbor BakeryStudioActive$49
Juniper FloralsPartnerActive$129
Linden YogaStarterTrial$19
Maple DentalStudioActive$49
Northwind BooksPartnerPast due$129

Made-up businesses, for the demo.

Code

Plain HTML for any site, or React. Both use the same styles, so the table looks the same wherever it lands.

ReadyAny website, Shopify, WordPress, Square, plain hosting

<link rel="stylesheet" href="tokens.css">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="parts.css">

<!-- Table: a caption names it. The first cell of each row is its header.
     prism-table--stack turns rows into cards on narrow widths; the roles keep it a table for screen readers. -->
<div class="prism-table-wrap" role="region" aria-labelledby="clients-cap" tabindex="0">
  <table class="prism-table prism-table--stack" role="table">
    <caption id="clients-cap">Clients</caption>
    <thead role="rowgroup">
      <tr role="row">
        <th scope="col" role="columnheader" aria-sort="ascending">
          <button type="button" class="prism-table__sort">Client<svg class="prism-table__arrow" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.8" aria-hidden="true"><path d="M8 12V4M4.5 7.5L8 4l3.5 3.5" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
        </th>
        <th scope="col" role="columnheader">Plan</th>
        <th scope="col" role="columnheader">Status</th>
        <th scope="col" role="columnheader" class="prism-table__num">Monthly</th>
      </tr>
    </thead>
    <tbody role="rowgroup">
      <tr role="row">
        <th scope="row" role="rowheader">Harbor Bakery</th>
        <td role="cell" data-label="Plan">Studio</td>
        <td role="cell" data-label="Status"><span class="prism-badge prism-badge--success">Active</span></td>
        <td role="cell" data-label="Monthly" class="prism-table__num">$49</td>
      </tr>
      <!-- more rows -->
    </tbody>
  </table>
</div>
<!-- Sorting: when a header button is pressed, re-order the rows, and move aria-sort
     ("ascending" or "descending") to that header. Only one header has aria-sort at a time. -->

Accessibility