Table
@codeui/styles v0.3.0
A native data table in plain HTML, styled by size and stripe attributes.
Load @codeui/styles/table.css, or all.css. The Solid component is documented in Table.
Demo
<div class="cui-table-scroll-area" data-cui="table-scroll-area" role="region" tabindex="0" aria-label="Export formats"> <table class="cui-table" data-cui="table" data-size="md"> <caption>Export formats</caption> <thead> <tr> <th scope="col">Format</th> <th scope="col">Use</th> <th scope="col" style="text-align: end">Scale</th> </tr> </thead> <tbody> <tr> <th scope="row">PNG</th> <td>High-resolution screenshots</td> <td style="text-align: end">2×</td> </tr> <tr> <th scope="row">JPEG</th> <td>Smaller files for sharing</td> <td style="text-align: end">1×</td> </tr> <tr> <th scope="row">SVG</th> <td>Scalable artwork</td> <td style="text-align: end">Any</td> </tr> </tbody> </table></div>Markup
| Part | Element | Class | data-cui |
|---|---|---|---|
| Scroll area | div | cui-table-scroll-area | table-scroll-area |
| Root | table | cui-table | table |
The root styles its own caption, thead, tbody, tfoot, tr, th and td children. They take no classes. The rules use child combinators, so rows must sit directly in a row group.
| Attribute | Values | Default |
|---|---|---|
data-size | sm, md | md |
data-striped | Presence | Off |
Variants
Size
<div class="cui-table-scroll-area" data-cui="table-scroll-area" role="region" tabindex="0" aria-label="Export formats"> <table class="cui-table" data-cui="table" data-size="sm"> <caption>Export formats</caption> <thead> <tr> <th scope="col">Format</th> <th scope="col">Use</th> <th scope="col" style="text-align: end">Scale</th> </tr> </thead> <tbody> <tr> <th scope="row">PNG</th> <td>High-resolution screenshots</td> <td style="text-align: end">2×</td> </tr> <tr> <th scope="row">JPEG</th> <td>Smaller files for sharing</td> <td style="text-align: end">1×</td> </tr> <tr> <th scope="row">SVG</th> <td>Scalable artwork</td> <td style="text-align: end">Any</td> </tr> </tbody> </table></div>md rows are 36px tall with 12px inline padding and 13px text. sm rows are 28px tall with 8px inline padding and 12px text. Omitting data-size renders md.
Striped rows
<div class="cui-table-scroll-area" data-cui="table-scroll-area" role="region" tabindex="0" aria-label="Export formats"> <table class="cui-table" data-cui="table" data-size="md" data-striped> <caption>Export formats</caption> <thead> <tr> <th scope="col">Format</th> <th scope="col">Use</th> <th scope="col" style="text-align: end">Scale</th> </tr> </thead> <tbody> <tr> <th scope="row">PNG</th> <td>High-resolution screenshots</td> <td style="text-align: end">2×</td> </tr> <tr> <th scope="row">JPEG</th> <td>Smaller files for sharing</td> <td style="text-align: end">1×</td> </tr> <tr> <th scope="row">SVG</th> <td>Scalable artwork</td> <td style="text-align: end">Any</td> </tr> <tr> <th scope="row">WebP</th> <td>Small files with transparency</td> <td style="text-align: end">2×</td> </tr> <tr> <th scope="row">PDF</th> <td>Print and slides</td> <td style="text-align: end">Vector</td> </tr> </tbody> </table></div>data-striped gives even body rows a half-strength field fill.
Scroll area
<div class="cui-table-scroll-area" data-cui="table-scroll-area" role="region" tabindex="0" aria-label="Recent snippets" style="max-width: 420px; margin-inline: auto"> <table class="cui-table" data-cui="table" data-size="md" style="min-width: 640px"> <caption>Recent snippets</caption> <thead> <tr> <th scope="col">Snippet</th> <th scope="col">Language</th> <th scope="col">Theme</th> <th scope="col">Font</th> <th scope="col">Padding</th> <th scope="col" style="text-align: end">Lines</th> </tr> </thead> <tbody> <tr> <th scope="row">fetch-retry.ts</th> <td>TypeScript</td> <td>Vitesse Dark</td> <td>JetBrains Mono</td> <td>64 px</td> <td style="text-align: end">42</td> </tr> <tr> <th scope="row">useDebounce.tsx</th> <td>TSX</td> <td>Dracula</td> <td>Fira Code</td> <td>32 px</td> <td style="text-align: end">18</td> </tr> <tr> <th scope="row">main.rs</th> <td>Rust</td> <td>One Dark</td> <td>Iosevka</td> <td>48 px</td> <td style="text-align: end">120</td> </tr> </tbody> </table></div>Wrap a wide table in the scroll area. It scrolls horizontally and clips to the row radius. Give it role="region", an accessible name and tabindex="0", so keyboard users can focus it and scroll with the arrow keys. It shows the focus ring on :focus-visible.
States
The table has no state attributes. Header cells use the field fill with muted 12px text. Body rows have no fill and no lines. Their first and last cells take the 10px row radius, so a striped fill, or one you add, reads as one rounded row. Numbers use tabular figures.
Cells inherit the start alignment. Set text-align: end on numeric columns, or use the align attribute, which the CSS respects.
What you supply
scope="col"on column headers andscope="row"on row headers.- A
caption, oraria-labelon the table, that names it. - Sorting, selection and pagination. The styles have no sort or selected-row states.
Helper
import "@codeui/styles/table.css";
import { applyStyleProps } from "@codeui/styles";
import { tableStyleProps } from "@codeui/styles/table";
const table = document.querySelector("table")!;
applyStyleProps(table, tableStyleProps({ size: "sm", striped: true }));
// class="cui-table" data-cui="table" data-size="sm" data-striped=""