Data DisplayFreeUses XON
Sortable and Filterable Table
A real table whose headers sort, with a text filter, five rows a page and a status line. The rows are plain HTML. Written with XON's table part.
A bar chart drawn as inline SVG from one data list, with a table view, a sort switch and focusable bars that read out their value.
Checked on 3 December 2026 in Chrome 143.0.7499.169: 12 automated checks. What the checks are
<figure class="bc" aria-labelledby="bc-title">
<div class="bc__head">
<div>
<p class="bc__eyebrow">Example data</p>
<h2 class="bc__title" id="bc-title">Cups of tea per weekday</h2>
</div>
<fieldset class="bc__seg">
<legend class="bc__sr">View</legend>
<label class="bc__opt"><input type="radio" name="bc-view" value="chart" data-model="bc.mode"><span>Chart</span></label>
<label class="bc__opt"><input type="radio" name="bc-view" value="table" data-model="bc.mode"><span>Table</span></label>
</fieldset>
</div>
<label class="bc__sort"><input type="checkbox" id="bc-sort" data-model="bc.sorted"><span>Highest first</span></label>
<div class="bc__body" data-if="bc.mode == 'chart'">
<ul class="bc__list" data-each="bc.rows" data-each-key="day">
<li class="bc__item">
<button type="button" class="bc__row" data-day="{day}" data-class-active="{day} == bc.active" data-on-focus="peek" data-on-click="pick" data-on-mouseenter="peek">
<span class="bc__day">{day}</span>
<svg class="bc__bar" viewBox="0 0 100 10" preserveAspectRatio="none" aria-hidden="true" focusable="false">
<rect class="bc__track" width="100" height="10"></rect>
<rect class="bc__fill" height="10" data-attr-width="{pct}"></rect>
</svg>
<span class="bc__value">{cups}</span>
</button>
</li>
</ul>
<p class="bc__readout" role="status" data-text="bc.readout"></p>
</div>
<div class="bc__body" data-if="bc.mode == 'table'">
<table class="bc__table">
<caption class="bc__sr">Cups of tea per weekday, example data</caption>
<thead><tr><th scope="col">Day</th><th scope="col">Cups</th></tr></thead>
<tbody data-each="bc.rows" data-each-key="day">
<tr><th scope="row">{day}</th><td>{cups}</td></tr>
</tbody>
</table>
</div>
<figcaption class="bc__summary" data-text="bc.summary"></figcaption>
</figure>.bc {
--bc-surface: #ffffff;
--bc-ink: #18262b;
--bc-muted: #4d6169;
--bc-line: #d3dfe2;
--bc-track: #e4edef;
--bc-fill: #167d86;
--bc-fill-hi: #0b4f57;
--bc-seg: #eef4f5;
--bc-on: #ffffff;
--bc-ring: #0f2b31;
box-sizing: border-box;
width: min(100%, 34rem);
margin: 0;
padding: 1.25rem;
color: var(--bc-ink);
background: var(--bc-surface);
border: 1px solid var(--bc-line);
border-radius: 16px;
box-shadow: 0 1px 2px rgb(24 38 43 / 6%), 0 10px 28px -12px rgb(24 38 43 / 22%);
font: 1rem/1.45 system-ui, system, "Segoe UI", Roboto, sans-serif;
}
.bc *, .bc *::before, .bc *::after { box-sizing: border-box; }
.bc__sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.bc__head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 0.75rem 1rem; }
.bc__eyebrow { margin: 0 0 0.15rem; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--bc-muted); }
.bc__title { margin: 0; font-size: 1.2rem; line-height: 1.25; }
.bc__seg { display: inline-flex; margin: 0; padding: 3px; gap: 2px; border: 0; background: var(--bc-seg); border-radius: 10px; }
.bc__opt { position: relative; display: inline-block; }
.bc__opt input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; appearance: none; background: transparent; border: 0; border-radius: 8px; cursor: pointer; z-index: 0; }
.bc__opt span { position: relative; display: block; min-width: 4.25rem; padding: 0.5rem 0.9rem; text-align: center; font-weight: 600; font-size: 0.9rem; color: var(--bc-muted); z-index: 1; cursor: pointer; }
.bc__opt input:checked { background: var(--bc-surface); box-shadow: 0 1px 3px rgb(24 38 43 / 22%); }
.bc__opt input:checked + span { color: var(--bc-ink); }
.bc__opt input:focus-visible { outline: 3px solid var(--bc-ring); outline-offset: 1px; }
.bc__sort { display: inline-flex; align-items: center; gap: 0.5rem; margin: 1rem 0 0.5rem; min-height: 24px; font-size: 0.9rem; color: var(--bc-muted); cursor: pointer; }
.bc__sort input { width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--bc-fill); }
.bc__sort input:focus-visible { outline: 3px solid var(--bc-ring); outline-offset: 2px; }
.bc__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.bc__row {
display: grid; grid-template-columns: 5.75rem 1fr 2.25rem; align-items: center; gap: 0.75rem; width: 100%; min-height: 44px;
padding: 0.25rem 0.5rem; font: inherit; color: var(--bc-ink); text-align: left; background: transparent; border: 0; border-radius: 10px; cursor: pointer;
}
.bc__row.active { background: var(--bc-seg); }
.bc__row:focus-visible { outline: 3px solid var(--bc-ring); outline-offset: 0; }
.bc__day { font-size: 0.9rem; font-weight: 600; }
.bc__bar { display: block; width: 100%; height: 14px; border-radius: 7px; overflow: hidden; }
.bc__track { fill: var(--bc-track); }
.bc__fill { fill: var(--bc-fill); transition: width 0.3s ease; }
.bc__row.active .bc__fill { fill: var(--bc-fill-hi); }
.bc__value { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.bc__readout { min-height: 1.5em; margin: 0.75rem 0 0; padding: 0.55rem 0.75rem; font-size: 0.9rem; color: var(--bc-ink); background: var(--bc-seg); border-radius: 10px; }
.bc__table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.bc__table th, .bc__table td { padding: 0.6rem 0.5rem; text-align: left; border-bottom: 1px solid var(--bc-line); }
.bc__table thead th { font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--bc-muted); }
.bc__table td { text-align: right; font-weight: 700; }
.bc__table thead th:last-child { text-align: right; }
.bc__table tbody th { font-weight: 600; }
.bc__summary { margin: 1rem 0 0; font-size: 0.85rem; color: var(--bc-muted); }
@media (max-width: 26rem) {
.bc { padding: 1rem; }
.bc__row { grid-template-columns: 5.5rem 1fr 1.75rem; gap: 0.5rem; padding-inline: 0.35rem; }
}
@media (prefers-color-scheme: dark) {
.bc {
--bc-surface: #15262b; --bc-ink: #e8f1f3; --bc-muted: #a9bec4; --bc-line: #2c444b; --bc-track: #223a41;
--bc-fill: #4cc3cf; --bc-fill-hi: #9be6ee; --bc-seg: #1d3339; --bc-ring: #e8f1f3;
box-shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 12px 30px -12px rgb(0 0 0 / 60%);
}
.bc__opt input:checked { background: #2a4850; }
}
@media (prefers-reduced-motion: reduce) {
.bc__fill { transition: none; }
}(function () {
'use strict';
var bc = xon.data('bc', {
mode: 'chart',
sorted: false,
active: '',
data: [
{ day: 'Monday', cups: 14 }, { day: 'Tuesday', cups: 22 }, { day: 'Wednesday', cups: 18 },
{ day: 'Thursday', cups: 27 }, { day: 'Friday', cups: 31 }, { day: 'Saturday', cups: 9 }, { day: 'Sunday', cups: 6 }
]
});
function maxOf(list) {
return list.reduce(function (m, r) { return r.cups > m ? r.cups : m; }, 0);
}
// The rows the chart and the table both show: the data, with a bar length, in the chosen order.
xon.calc('bc.rows', function (s) {
var top = maxOf(s.data);
var rows = s.data.map(function (r, i) { return { day: r.day, cups: r.cups, pct: Math.round(r.cups / top * 1000) / 10, i: i }; });
if (s.sorted) rows.sort(function (a, b) { return b.cups - a.cups || a.i - b.i; });
return rows;
});
xon.calc('bc.readout', function (s) {
var row = s.data.filter(function (r) { return r.day === s.active; })[0];
if (!row) return 'Move to a bar to read its value.';
var top = maxOf(s.data);
return row.day + ': ' + row.cups + ' cups' + (row.cups === top ? ', the most of the week.' : '.');
});
xon.calc('bc.summary', function (s) {
var hi = s.data.reduce(function (a, r) { return r.cups > a.cups ? r : a; });
var lo = s.data.reduce(function (a, r) { return r.cups < a.cups ? r : a; });
return 'Example data. ' + hi.day + ' is the highest with ' + hi.cups + ' cups; ' + lo.day + ' is the lowest with ' + lo.cups + '.';
});
function pick(event, button) { bc.active = button.dataset.day; }
// Focus and hover happen without a click, so this one is offered as a function that only shows something.
function peek(event, button) { bc.active = button.dataset.day; }
xon.use(pick);
xon.use.auto(peek);
})();Written by the author of the snippet. Each note has a test step or a markup check that reads the page.
Data DisplayA real table whose headers sort, with a text filter, five rows a page and a status line. The rows are plain HTML. Written with XON's table part.
Data DisplayA table with caption, scoped headers and right-aligned numbers that reflows into labelled stacked cards on a phone, in plain CSS.