Filter a small local collection without interrupting typing or treating text as code.
HTML + CSS + JavaScript
setTimeout(filterItems, 250) Interaction · Complete runnable example
Sort the rows already on the page while preserving ties and explaining the current order.
This preview runs in an isolated document. Clipboard writes and saved preferences may be blocked, and printing requires the standalone file. A dialog affects only the example. Reset reloads the original example state.
Use this pattern for a small table that readers need to compare in different orders. The example keeps native table structure and places real buttons inside the sortable column headers.
The preview, copied text, and downloaded file use this same document.
<!doctype html>
<!--
MIT License
Copyright (c) 2026 MRHTML
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'unsafe-inline'; script-src 'unsafe-inline'; img-src data: blob:; connect-src 'none'; form-action 'none'; object-src 'none'; base-uri 'none'"
/>
<title>MRHTML | A little order, please.</title>
<style>
:root {
font-family: Arial, Helvetica, sans-serif;
color-scheme: light;
--ink: #192f34;
--muted: #56666a;
--paper: #f6f5f0;
--line: #cdd5d0;
--accent: #186354;
--soft: #e7efe5;
--mono: Consolas, 'Liberation Mono', monospace;
}
* {
box-sizing: border-box;
}
html {
scroll-padding-top: 90px;
}
body {
margin: 0;
background: var(--paper);
color: var(--ink);
line-height: 1.6;
}
h1,
h2,
h3,
p {
margin: 0;
}
h1,
h2,
h3 {
font-weight: 500;
letter-spacing: -0.045em;
line-height: 1.1;
}
h1 {
font-size: clamp(38px, 5.5vw, 65px);
}
h2 {
font-size: 29px;
}
h3 {
font-size: 21px;
}
p {
overflow-wrap: anywhere;
}
a {
color: var(--accent);
text-underline-offset: 4px;
}
button,
select {
font: inherit;
color: inherit;
}
button {
cursor: pointer;
}
button,
a,
summary {
touch-action: manipulation;
}
button:focus-visible,
a:focus-visible,
select:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
outline: 3px solid #a94823;
outline-offset: 4px;
}
[hidden] {
display: none !important;
}
.wrap {
width: min(1050px, calc(100% - 64px));
margin-inline: auto;
}
.header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 20px;
padding: 28px 0;
border-bottom: 1px solid var(--line);
}
.brand {
font-size: 15px;
font-weight: 700;
display: flex;
align-items: center;
gap: 10px;
letter-spacing: -0.5px;
}
.mark {
display: grid;
place-items: center;
width: 28px;
height: 28px;
background: var(--accent);
color: #fff;
font-weight: bold;
font-size: 18px;
}
.header > p,
.eyebrow,
.small {
font: 10px/1.7 var(--mono);
letter-spacing: 0.03em;
}
.header > p {
color: var(--muted);
}
main {
padding-block: 43px 50px;
}
.intro {
margin-bottom: 30px;
max-width: 720px;
}
.eyebrow {
color: var(--accent);
margin-bottom: 13px;
}
.intro > p:last-child {
font-size: 15px;
max-width: 570px;
color: var(--muted);
margin-top: 18px;
}
.surface {
background: #fff;
border: 1px solid var(--line);
border-radius: 14px;
box-shadow: 0 12px 32px #263e3010;
}
.button {
border: 1px solid var(--accent);
background: var(--accent);
color: #fff;
padding: 10px 16px;
min-height: 43px;
border-radius: 7px;
font-size: 13px;
font-weight: 600;
}
.button.secondary {
background: #fff;
color: var(--accent);
border-color: #a9bbb0;
}
.button[aria-disabled='true'],
button:disabled {
background: #edf0e9;
color: #5d695f;
border-color: #c9d1c4;
cursor: default;
}
.status {
font-size: 12px;
color: var(--muted);
min-height: 22px;
}
.note {
font-size: 12px;
color: var(--muted);
margin-top: 20px;
max-width: 75ch;
}
.footer {
display: flex;
justify-content: space-between;
gap: 20px;
padding-block: 22px;
border-top: 1px solid var(--line);
font-size: 10px;
color: var(--muted);
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
noscript p {
padding: 15px;
background: #e8ece2;
border-left: 3px solid var(--accent);
font-size: 13px;
margin-bottom: 20px;
}
code,
kbd {
font: 12px var(--mono);
}
kbd {
border: 1px solid #bcc7bd;
border-radius: 4px;
padding: 2px 5px;
background: #fff;
}
button:disabled:focus {
outline: none;
}
@media (max-width: 600px) {
.wrap {
width: calc(100% - 36px);
}
.header {
padding-block: 22px;
}
.header > p {
font-size: 8px;
max-width: 105px;
text-align: right;
}
.brand {
font-size: 13px;
gap: 8px;
}
main {
padding-block: 30px 35px;
}
.intro {
margin-bottom: 26px;
}
.intro > p:last-child {
font-size: 14px;
}
.eyebrow {
font-size: 9px;
}
h1 {
font-size: 40px;
}
.footer {
flex-wrap: wrap;
font-size: 9px;
}
}
@media (max-width: 350px) {
h1 {
font-size: 35px;
}
.button {
padding: 10px 12px;
font-size: 12px;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation: none !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
.table-surface {
overflow: hidden;
}
.table-heading {
padding: 24px 27px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
background: #e7efe5;
}
.table-heading h2 {
font-size: 26px;
}
.table-heading .small {
color: #435d4c;
font-size: 9px;
}
.table-scroll {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
text-align: left;
}
caption {
text-align: left;
padding: 18px 27px;
color: var(--muted);
font-size: 12px;
}
th,
td {
border-bottom: 1px solid #e0e5dd;
padding: 18px 27px;
font-size: 14px;
}
thead {
background: #f4f6f1;
}
thead th {
padding: 0;
font-weight: 500;
}
thead button {
border: 0;
width: 100%;
min-height: 56px;
display: flex;
gap: 16px;
align-items: center;
justify-content: space-between;
padding: 15px 27px;
background: transparent;
font-size: 12px;
font-weight: 600;
text-align: left;
}
thead button:disabled {
background: transparent;
}
thead button:focus-visible {
outline-offset: -4px;
}
thead span {
color: var(--accent);
}
tbody th {
font-weight: 500;
width: 50%;
}
td {
font-size: 12px;
white-space: nowrap;
}
tbody tr:last-child > * {
border-bottom: 0;
}
#sort-status {
padding: 18px 27px;
border-top: 1px solid var(--line);
}
@media (max-width: 600px) {
.table-heading {
padding: 20px;
}
.table-heading .small {
font-size: 7px;
}
caption {
padding: 16px 18px;
}
th,
td {
padding: 17px 12px;
}
tbody th {
font-size: 13px;
}
td {
font-size: 11px;
white-space: normal;
}
thead button {
padding: 14px 12px;
font-size: 11px;
gap: 8px;
}
#sort-status {
padding: 16px 18px;
font-size: 11px;
}
}
</style>
</head>
<body>
<header class="header wrap">
<span class="brand"
><span class="mark" aria-hidden="true">m.</span>MRHTML / Workshop</span
>
<p>SMALL PATTERNS.<br />CONSIDERED DETAILS.</p>
</header>
<main class="wrap">
<div class="intro">
<p class="eyebrow">01 / SORTABLE TABLE</p>
<h1>A little order, please.</h1>
<p>
Explore a fictional workshop reading list. Sort by title, reading
time, or review date. Equal values keep their original order.
</p>
</div>
<noscript
><p>
All entries remain readable. Turn on JavaScript to sort the table.
</p></noscript
>
<div class="surface table-surface">
<div class="table-heading">
<h2>Reading desk</h2>
<span class="small">6 SAMPLE ENTRIES</span>
</div>
<div
class="table-scroll"
role="region"
aria-label="Sortable reading list"
tabindex="0"
>
<table>
<caption>
Workshop reading list.
<span id="sort-help">All six entries are shown.</span>
</caption>
<thead>
<tr>
<th scope="col">
<button
type="button"
data-column="0"
data-type="text"
disabled
>
Title <span aria-hidden="true">↕</span>
</button>
</th>
<th scope="col">
<button
type="button"
data-column="1"
data-type="number"
disabled
>
Minutes <span aria-hidden="true">↕</span>
</button>
</th>
<th scope="col">
<button
type="button"
data-column="2"
data-type="date"
disabled
>
Reviewed <span aria-hidden="true">↕</span>
</button>
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Make room for focus</th>
<td data-value="12">12 min</td>
<td data-value="2026-09-08">
<time datetime="2026-09-08">8 Sep 2026</time>
</td>
</tr>
<tr>
<th scope="row">A useful first draft</th>
<td data-value="5">5 min</td>
<td data-value="2026-08-21">
<time datetime="2026-08-21">21 Aug 2026</time>
</td>
</tr>
<tr>
<th scope="row">Working in the open</th>
<td data-value="12">12 min</td>
<td data-value="2026-09-02">
<time datetime="2026-09-02">2 Sep 2026</time>
</td>
</tr>
<tr>
<th scope="row">Notes for the next person</th>
<td data-value="8">8 min</td>
<td data-value="2026-09-08">
<time datetime="2026-09-08">8 Sep 2026</time>
</td>
</tr>
<tr>
<th scope="row">Small steps, clear choices</th>
<td data-value="20">20 min</td>
<td data-value="2026-07-14">
<time datetime="2026-07-14">14 Jul 2026</time>
</td>
</tr>
<tr>
<th scope="row">An unfinished question</th>
<td data-value="">Not set</td>
<td data-value="">Not reviewed</td>
</tr>
</tbody>
</table>
</div>
<p
id="sort-status"
class="status"
role="status"
aria-live="polite"
aria-atomic="true"
>
Original order. Missing values always sort last.
</p>
</div>
<p class="note">
Column buttons toggle ascending and descending order. This example sorts
the existing rows; it does not load records or save your preference.
</p>
</main>
<footer class="footer wrap">
<span>MRHTML / Original runnable example</span
><span>Local content. No network required.</span>
</footer>
<script>
(() => {
'use strict';
const body = document.querySelector('tbody');
const records = [...body.rows].map((row, index) => ({ row, index }));
const buttons = [...document.querySelectorAll('[data-column]')];
const collator = new Intl.Collator('en', {
sensitivity: 'base',
numeric: false,
});
let column = null,
ascending = true;
function value(record, index, type) {
const cell = record.row.cells[index];
const raw =
cell.dataset.value === undefined
? cell.textContent.trim()
: cell.dataset.value;
if (raw === '') return null;
if (type === 'number') {
const number = Number(raw);
return Number.isFinite(number) ? number : null;
}
if (type === 'date') {
const number = Date.parse(raw);
return Number.isFinite(number) ? number : null;
}
return raw;
}
buttons.forEach((button) => {
button.addEventListener('click', () => {
const next = Number(button.dataset.column);
ascending = column === next ? !ascending : true;
column = next;
const sorted = [...records].sort((a, b) => {
const av = value(a, column, button.dataset.type),
bv = value(b, column, button.dataset.type);
if (av === null || bv === null)
return av === bv ? a.index - b.index : av === null ? 1 : -1;
const compared =
button.dataset.type === 'text'
? collator.compare(av, bv)
: av - bv;
return compared === 0
? a.index - b.index
: compared * (ascending ? 1 : -1);
});
sorted.forEach((record) => body.append(record.row));
buttons.forEach((item) => {
item.closest('th').removeAttribute('aria-sort');
item.querySelector('span').textContent = '↕';
});
button
.closest('th')
.setAttribute(
'aria-sort',
ascending ? 'ascending' : 'descending',
);
button.querySelector('span').textContent = ascending ? '↑' : '↓';
document.querySelector('#sort-status').textContent =
`Sorted by ${button.childNodes[0].textContent.trim().toLowerCase()}, ${ascending ? 'ascending' : 'descending'}. ${records.length} entries. Missing values last.`;
});
button.disabled = false;
});
document.querySelector('#sort-help').textContent =
'Column buttons change the sort order.';
})();
</script>
</body>
</html>