domestic-ui GitHub

Data table

Rows of records in a native <table> with a caption, header cells and optional sorting.

Where a data table is used A data table fills the content area under the page heading: a caption, a header row and one row per record, with sortable columns.

Live example

Sortable table

<dui-table>
  <section data-scroll="inline" aria-labelledby="sort-caption" tabindex="0">
    <table data-table id="sort-table">
      <caption id="sort-caption">Recent orders</caption>
      <thead>
        <tr>
          <th scope="col" data-table-cell="sortable">Order</th>
          <th scope="col" data-table-cell="sortable">Customer</th>
          <th scope="col" data-table-cell="sortable">Placed</th>
          <th scope="col" data-table-cell="sortable">Status</th>
          <th scope="col" data-table-cell="sortable number">Total</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1042</th>
          <td>Analytical Engines Ltd.</td>
          <td><time datetime="2025-03-12">12 Mar 2025</time></td>
          <td><span data-badge="accent">Shipped</span></td>
          <td data-table-cell="number">€1,240.00</td>
        </tr>
        <tr>
          <th scope="row">1041</th>
          <td>Bletchley Instruments</td>
          <td><time datetime="2025-03-10">10 Mar 2025</time></td>
          <td><span data-badge="success">Delivered</span></td>
          <td data-table-cell="number">€48.50</td>
        </tr>
        <tr>
          <th scope="row">1040</th>
          <td>Cobol Systems BV</td>
          <td><time datetime="2025-03-09">9 Mar 2025</time></td>
          <td><span data-badge="neutral">Open</span></td>
          <td data-table-cell="number">€3,980.00</td>
        </tr>
        <tr>
          <th scope="row">1039</th>
          <td>Orbital Mechanics GmbH</td>
          <td><time datetime="2025-03-07">7 Mar 2025</time></td>
          <td><span data-badge="warning">On hold</span></td>
          <td data-table-cell="number">€615.90</td>
        </tr>
        <tr>
          <th scope="row">1038</th>
          <td>Difference Engine Works</td>
          <td><time datetime="2025-02-27">27 Feb 2025</time></td>
          <td><span data-badge="success">Delivered</span></td>
          <td data-table-cell="number">€310.25</td>
        </tr>
        <tr>
          <th scope="row">1037</th>
          <td>Hollerith Tabulating Co.</td>
          <td><time datetime="2025-03-01">1 Mar 2025</time></td>
          <td><span data-badge="danger">Cancelled</span></td>
          <td data-table-cell="number">€72.00</td>
        </tr>
        <tr>
          <th scope="row">1036</th>
          <td>Lovelace Analytics</td>
          <td><time datetime="2025-02-24">24 Feb 2025</time></td>
          <td><span data-badge="accent">Shipped</span></td>
          <td data-table-cell="number">€12,450.00</td>
        </tr>
        <tr>
          <th scope="row">1035</th>
          <td>Turing Logistics</td>
          <td><time datetime="2025-02-28">28 Feb 2025</time></td>
          <td><span data-badge="neutral">Open</span></td>
          <td data-table-cell="number">€905.10</td>
        </tr>
      </tbody>
    </table>
  </section>
</dui-table>

Selection and bulk actions

<form id="bulk-form" method="post" action="?">
  <dui-table id="bulk-orders" class="stack" select-all-label="Select all open orders" style="--stack-gap: var(--dui-space-s)">
    <div class="cluster">
      <dui-toolbar role="toolbar" aria-label="Bulk actions">
        <button type="submit" name="action" value="ship" data-button="secondary" id="bulk-ship">Mark as shipped</button>
        <button type="submit" name="action" value="print" data-button="secondary" id="bulk-print">Print packing slips</button>
        <button type="submit" name="action" value="export" data-button="secondary" id="bulk-export">Export</button>
      </dui-toolbar>
      <p role="status" id="selection-count"></p>
    </div>
    <section data-scroll="inline" aria-labelledby="select-caption" tabindex="0">
      <table data-table id="select-table">
        <caption id="select-caption">Open orders</caption>
        <thead>
          <tr>
            <td></td>
            <th scope="col">Order</th>
            <th scope="col">Customer</th>
            <th scope="col">Placed</th>
            <th scope="col">Status</th>
            <th scope="col" data-table-cell="number">Total</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><label><input type="checkbox" name="orders[]" value="1042"><span class="visually-hidden">Select order 1042</span></label></td>
            <th scope="row">1042</th>
            <td>Analytical Engines Ltd.</td>
            <td><time datetime="2025-03-12">12 Mar 2025</time></td>
            <td><span data-badge="accent">Shipped</span></td>
            <td data-table-cell="number">€1,240.00</td>
          </tr>
          <tr>
            <td><label><input type="checkbox" name="orders[]" value="1041"><span class="visually-hidden">Select order 1041</span></label></td>
            <th scope="row">1041</th>
            <td>Bletchley Instruments</td>
            <td><time datetime="2025-03-10">10 Mar 2025</time></td>
            <td><span data-badge="success">Delivered</span></td>
            <td data-table-cell="number">€48.50</td>
          </tr>
          <tr>
            <td><label><input type="checkbox" name="orders[]" value="1040"><span class="visually-hidden">Select order 1040</span></label></td>
            <th scope="row">1040</th>
            <td>Cobol Systems BV</td>
            <td><time datetime="2025-03-09">9 Mar 2025</time></td>
            <td><span data-badge="neutral">Open</span></td>
            <td data-table-cell="number">€3,980.00</td>
          </tr>
          <tr>
            <td><label><input type="checkbox" name="orders[]" value="1039"><span class="visually-hidden">Select order 1039</span></label></td>
            <th scope="row">1039</th>
            <td>Orbital Mechanics GmbH</td>
            <td><time datetime="2025-03-07">7 Mar 2025</time></td>
            <td><span data-badge="warning">On hold</span></td>
            <td data-table-cell="number">€615.90</td>
          </tr>
          <tr>
            <td><label><input type="checkbox" name="orders[]" value="1038"><span class="visually-hidden">Select order 1038</span></label></td>
            <th scope="row">1038</th>
            <td>Difference Engine Works</td>
            <td><time datetime="2025-02-27">27 Feb 2025</time></td>
            <td><span data-badge="success">Delivered</span></td>
            <td data-table-cell="number">€310.25</td>
          </tr>
          <tr>
            <td><label><input type="checkbox" name="orders[]" value="1037"><span class="visually-hidden">Select order 1037</span></label></td>
            <th scope="row">1037</th>
            <td>Hollerith Tabulating Co.</td>
            <td><time datetime="2025-03-01">1 Mar 2025</time></td>
            <td><span data-badge="danger">Cancelled</span></td>
            <td data-table-cell="number">€72.00</td>
          </tr>
        </tbody>
      </table>
    </section>
  </dui-table>
</form>
<p role="status" id="bulk-result"></p>

Empty state

<section data-scroll="inline" aria-labelledby="empty-caption" tabindex="0">
  <table data-table>
    <caption id="empty-caption">Orders on hold</caption>
    <thead>
      <tr>
        <th scope="col">Order</th>
        <th scope="col">Customer</th>
        <th scope="col">Placed</th>
        <th scope="col">Status</th>
        <th scope="col" data-table-cell="number">Total</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td colspan="5">
          <p>No orders match these filters</p>
          <p>Try another status or date, or <a href="?">clear the filters</a>.</p>
        </td>
      </tr>
    </tbody>
  </table>
</section>

Loading state

<p><button type="button" id="loading-toggle" aria-pressed="false" hidden>Show loading state</button></p>
<p role="status" id="loading-status"></p>
<section data-scroll="inline" aria-labelledby="loading-caption" tabindex="0">
  <table data-table id="loading-table">
    <caption id="loading-caption">Invoices</caption>
    <thead>
      <tr><th scope="col">Invoice</th><th scope="col">Customer</th><th scope="col">Due</th><th scope="col" data-table-cell="number">Amount</th></tr>
    </thead>
    <tbody>
        <tr><th scope="row">INV-2051</th><td>Cobol Systems BV</td><td><time datetime="2025-03-31">31 Mar 2025</time></td><td data-table-cell="number">€4,820.00</td></tr>
        <tr><th scope="row">INV-2050</th><td>Turing Logistics</td><td><time datetime="2025-03-28">28 Mar 2025</time></td><td data-table-cell="number">€1,105.40</td></tr>
        <tr><th scope="row">INV-2049</th><td>Lovelace Analytics</td><td><time datetime="2025-03-21">21 Mar 2025</time></td><td data-table-cell="number">€15,064.50</td></tr>
        <tr><th scope="row">INV-2048</th><td>Bletchley Instruments</td><td><time datetime="2025-03-14">14 Mar 2025</time></td><td data-table-cell="number">€58.69</td></tr>
    </tbody>
  </table>
</section>
<template id="loading-skeleton">
    <tr aria-hidden="true"><td></td><td></td><td></td><td></td></tr>
    <tr aria-hidden="true"><td></td><td></td><td></td><td></td></tr>
    <tr aria-hidden="true"><td></td><td></td><td></td><td></td></tr>
</template>

Wide table with a sticky header

<section data-scroll="block inline" aria-labelledby="wide-caption" tabindex="0" id="wide-scroll">
  <table data-table="sticky" id="wide-table">
    <caption id="wide-caption">Order lines, February</caption>
    <thead>
      <tr>
        <th scope="col">Order</th>
        <th scope="col">Customer</th>
        <th scope="col">Placed</th>
        <th scope="col">Ship by</th>
        <th scope="col">Status</th>
        <th scope="col">Carrier</th>
        <th scope="col">Warehouse</th>
        <th scope="col" data-table-cell="number">Items</th>
        <th scope="col" data-table-cell="number">Net</th>
        <th scope="col" data-table-cell="number">VAT</th>
        <th scope="col" data-table-cell="number">Total</th>
      </tr>
    </thead>
    <tbody>
        <tr>
          <th scope="row">1034</th>
          <td>Analytical Engines Ltd.</td>
          <td><time datetime="2025-02-26">26 Feb 2025</time></td>
          <td><time datetime="2025-03-09">9 Mar 2025</time></td>
          <td><span data-badge="neutral">Open</span></td>
          <td>DHL Express</td>
          <td>Rotterdam</td>
          <td data-table-cell="number">21</td>
          <td data-table-cell="number">€8,532.87</td>
          <td data-table-cell="number">€1,791.90</td>
          <td data-table-cell="number">€10,324.77</td>
        </tr>
        <tr>
          <th scope="row">1033</th>
          <td>Bletchley Instruments</td>
          <td><time datetime="2025-02-25">25 Feb 2025</time></td>
          <td><time datetime="2025-03-08">8 Mar 2025</time></td>
          <td><span data-badge="accent">Shipped</span></td>
          <td>DPD Classic</td>
          <td>Leipzig</td>
          <td data-table-cell="number">26</td>
          <td data-table-cell="number">€5,872.37</td>
          <td data-table-cell="number">€1,233.20</td>
          <td data-table-cell="number">€7,105.57</td>
        </tr>
        <tr>
          <th scope="row">1032</th>
          <td>Cobol Systems BV</td>
          <td><time datetime="2025-02-24">24 Feb 2025</time></td>
          <td><time datetime="2025-03-07">7 Mar 2025</time></td>
          <td><span data-badge="success">Delivered</span></td>
          <td>PostNL Parcel</td>
          <td>Lyon</td>
          <td data-table-cell="number">5</td>
          <td data-table-cell="number">€7,398.62</td>
          <td data-table-cell="number">€1,553.71</td>
          <td data-table-cell="number">€8,952.33</td>
        </tr>
        <tr>
          <th scope="row">1031</th>
          <td>Orbital Mechanics GmbH</td>
          <td><time datetime="2025-02-23">23 Feb 2025</time></td>
          <td><time datetime="2025-03-06">6 Mar 2025</time></td>
          <td><span data-badge="warning">On hold</span></td>
          <td>UPS Standard</td>
          <td>Milan</td>
          <td data-table-cell="number">7</td>
          <td data-table-cell="number">€3,316.57</td>
          <td data-table-cell="number">€696.48</td>
          <td data-table-cell="number">€4,013.05</td>
        </tr>
        <tr>
          <th scope="row">1030</th>
          <td>Difference Engine Works</td>
          <td><time datetime="2025-02-22">22 Feb 2025</time></td>
          <td><time datetime="2025-03-05">5 Mar 2025</time></td>
          <td><span data-badge="neutral">Open</span></td>
          <td>FedEx International</td>
          <td>Rotterdam</td>
          <td data-table-cell="number">4</td>
          <td data-table-cell="number">€8,190.95</td>
          <td data-table-cell="number">€1,720.10</td>
          <td data-table-cell="number">€9,911.05</td>
        </tr>
        <tr>
          <th scope="row">1029</th>
          <td>Hollerith Tabulating Co.</td>
          <td><time datetime="2025-02-21">21 Feb 2025</time></td>
          <td><time datetime="2025-03-04">4 Mar 2025</time></td>
          <td><span data-badge="accent">Shipped</span></td>
          <td>DHL Express</td>
          <td>Leipzig</td>
          <td data-table-cell="number">14</td>
          <td data-table-cell="number">€375.96</td>
          <td data-table-cell="number">€78.95</td>
          <td data-table-cell="number">€454.91</td>
        </tr>
        <tr>
          <th scope="row">1028</th>
          <td>Lovelace Analytics</td>
          <td><time datetime="2025-02-20">20 Feb 2025</time></td>
          <td><time datetime="2025-03-03">3 Mar 2025</time></td>
          <td><span data-badge="success">Delivered</span></td>
          <td>DPD Classic</td>
          <td>Lyon</td>
          <td data-table-cell="number">28</td>
          <td data-table-cell="number">€3,786.82</td>
          <td data-table-cell="number">€795.23</td>
          <td data-table-cell="number">€4,582.05</td>
        </tr>
        <tr>
          <th scope="row">1027</th>
          <td>Turing Logistics</td>
          <td><time datetime="2025-02-19">19 Feb 2025</time></td>
          <td><time datetime="2025-03-02">2 Mar 2025</time></td>
          <td><span data-badge="warning">On hold</span></td>
          <td>PostNL Parcel</td>
          <td>Milan</td>
          <td data-table-cell="number">16</td>
          <td data-table-cell="number">€852.79</td>
          <td data-table-cell="number">€179.09</td>
          <td data-table-cell="number">€1,031.88</td>
        </tr>
        <tr>
          <th scope="row">1026</th>
          <td>Analytical Engines Ltd.</td>
          <td><time datetime="2025-02-18">18 Feb 2025</time></td>
          <td><time datetime="2025-03-01">1 Mar 2025</time></td>
          <td><span data-badge="neutral">Open</span></td>
          <td>UPS Standard</td>
          <td>Rotterdam</td>
          <td data-table-cell="number">28</td>
          <td data-table-cell="number">€569.63</td>
          <td data-table-cell="number">€119.62</td>
          <td data-table-cell="number">€689.25</td>
        </tr>
        <tr>
          <th scope="row">1025</th>
          <td>Bletchley Instruments</td>
          <td><time datetime="2025-02-17">17 Feb 2025</time></td>
          <td><time datetime="2025-03-09">9 Mar 2025</time></td>
          <td><span data-badge="accent">Shipped</span></td>
          <td>FedEx International</td>
          <td>Leipzig</td>
          <td data-table-cell="number">37</td>
          <td data-table-cell="number">€1,149.27</td>
          <td data-table-cell="number">€241.35</td>
          <td data-table-cell="number">€1,390.62</td>
        </tr>
        <tr>
          <th scope="row">1024</th>
          <td>Cobol Systems BV</td>
          <td><time datetime="2025-02-16">16 Feb 2025</time></td>
          <td><time datetime="2025-03-08">8 Mar 2025</time></td>
          <td><span data-badge="success">Delivered</span></td>
          <td>DHL Express</td>
          <td>Lyon</td>
          <td data-table-cell="number">15</td>
          <td data-table-cell="number">€5,690.41</td>
          <td data-table-cell="number">€1,194.99</td>
          <td data-table-cell="number">€6,885.40</td>
        </tr>
        <tr>
          <th scope="row">1023</th>
          <td>Orbital Mechanics GmbH</td>
          <td><time datetime="2025-02-15">15 Feb 2025</time></td>
          <td><time datetime="2025-03-07">7 Mar 2025</time></td>
          <td><span data-badge="warning">On hold</span></td>
          <td>DPD Classic</td>
          <td>Milan</td>
          <td data-table-cell="number">38</td>
          <td data-table-cell="number">€8,531.47</td>
          <td data-table-cell="number">€1,791.61</td>
          <td data-table-cell="number">€10,323.08</td>
        </tr>
        <tr>
          <th scope="row">1022</th>
          <td>Difference Engine Works</td>
          <td><time datetime="2025-02-14">14 Feb 2025</time></td>
          <td><time datetime="2025-03-06">6 Mar 2025</time></td>
          <td><span data-badge="neutral">Open</span></td>
          <td>PostNL Parcel</td>
          <td>Rotterdam</td>
          <td data-table-cell="number">37</td>
          <td data-table-cell="number">€5,286.45</td>
          <td data-table-cell="number">€1,110.15</td>
          <td data-table-cell="number">€6,396.60</td>
        </tr>
        <tr>
          <th scope="row">1021</th>
          <td>Hollerith Tabulating Co.</td>
          <td><time datetime="2025-02-13">13 Feb 2025</time></td>
          <td><time datetime="2025-03-05">5 Mar 2025</time></td>
          <td><span data-badge="accent">Shipped</span></td>
          <td>UPS Standard</td>
          <td>Leipzig</td>
          <td data-table-cell="number">4</td>
          <td data-table-cell="number">€8,787.25</td>
          <td data-table-cell="number">€1,845.32</td>
          <td data-table-cell="number">€10,632.57</td>
        </tr>
        <tr>
          <th scope="row">1020</th>
          <td>Lovelace Analytics</td>
          <td><time datetime="2025-02-12">12 Feb 2025</time></td>
          <td><time datetime="2025-03-04">4 Mar 2025</time></td>
          <td><span data-badge="success">Delivered</span></td>
          <td>FedEx International</td>
          <td>Lyon</td>
          <td data-table-cell="number">3</td>
          <td data-table-cell="number">€5,027.72</td>
          <td data-table-cell="number">€1,055.82</td>
          <td data-table-cell="number">€6,083.54</td>
        </tr>
        <tr>
          <th scope="row">1019</th>
          <td>Turing Logistics</td>
          <td><time datetime="2025-02-11">11 Feb 2025</time></td>
          <td><time datetime="2025-03-03">3 Mar 2025</time></td>
          <td><span data-badge="warning">On hold</span></td>
          <td>DHL Express</td>
          <td>Milan</td>
          <td data-table-cell="number">9</td>
          <td data-table-cell="number">€2,634.90</td>
          <td data-table-cell="number">€553.33</td>
          <td data-table-cell="number">€3,188.23</td>
        </tr>
    </tbody>
  </table>
</section>

Attributes

Attribute or valueWhereEffect
data-tablethe <table>header surface, sort buttons, selection, empty and loading states
data-table="sticky"the <table>the header row sticks to the nearest scroll container
data-table-cell="number"every <th> and <td> of a numeric columnend-aligned, tabular, no wrapping
data-table-cell="sortable"a <thead> <th><dui-table> turns its text into a sort button
aria-sort="ascending | descending"the sorted <th> only (native ARIA)
aria-busy="true"the <table> while rows load

Cells

Words on the table cannot target a column, so number and sortable go on each cell, in data-table-cell.

Selection

A <label> with a checkbox and visually hidden text naming the row ("Select order 1042") in the first cell of each body row, and an empty first header cell, where <dui-table> adds the "select all" checkbox.

Empty

One row with a single <td colspan> holding a message and an optional action.

Loading

aria-busy="true" on the table and skeleton rows of empty <td>s with aria-hidden="true"; the empty cells show as bars.

Keyboard

KeyAction
Tabmoves to the scroll container, then each sort button and checkbox
Enter / Spaceon a sort button, sorts by that column (again: reverses)
Spaceon a checkbox, selects or deselects the row (or every row)
Arrow keysscroll the focused scroll container

Accessibility

  • Our choice: sortable headers are plain text in the markup and the script turns them into buttons, so with JavaScript off there are no buttons that do nothing; the rows keep the server's order, which aria-sort in the markup can state.
  • Our choice: a selected row is marked by its checked checkbox, a bar on its leading edge and a tinted background, so selection never relies on color alone (WCAG 1.4.1).
  • The rows stay rows of a table, not a grid: aria-selected is only allowed on rows of a grid or treegrid, so the checkbox carries the state.
  • The scroll container (or the page) gets a scroll-padding-block-start the height of the header, so a focused checkbox is never hidden under it (WCAG 2.4.11).
  • Each row checkbox has a name that says which row it selects ("Select order 1042"), from a visually hidden label text; the selection count is a role="status" region present from page load, so changes are announced politely (WCAG 4.1.3).
  • A loading table has aria-busy="true" and its skeleton rows have aria-hidden="true", so a screen reader hears the caption, the column headers and the page's status message ("Loading orders"), not blank cells.
  • The skeleton shimmer stops under reduced motion and data-motion="none".
  • Header buttons and checkbox labels are --dui-size-control tall (36px, 32px compact, 44px on touch), above the 24px of WCAG 2.5.8.
  • Those make the table an APG Grid, which this is not.

Specifications

See also

How other systems do it

For comparison only; these are not the standard this system follows.

Search