Skip to the main content

To-do List

FreeUses XON Utilities

A small task list with add, tick, delete, filter and clear-done, with the count announced in a live region and nothing sent anywhere.

Checked on 3 December 2026 in Chrome 143.0.7499.169: 12 automated checks. What the checks are

Preview and code

HTML

<section class="td" aria-labelledby="td-title">
  <header class="td__head">
    <div>
      <p class="td__eyebrow">Example list</p>
      <h2 class="td__title" id="td-title">Today</h2>
    </div>
    <p class="td__count" role="status" data-text="td.status"></p>
  </header>

  <progress class="td__progress" max="100" value="0" data-attr-value="td.percent" aria-label="Share of tasks done"></progress>

  <form class="td__form" data-on-submit="addTask">
    <label class="td__sr" for="td-new">New task</label>
    <input class="td__input" id="td-new" type="text" autocomplete="off" maxlength="80" placeholder="Add a task" data-model="td.draft">
    <button class="td__add" type="submit">Add</button>
  </form>

  <fieldset class="td__filters">
    <legend class="td__sr">Show</legend>
    <label class="td__pill"><input type="radio" name="td-filter" value="all" data-model="td.filter"><span>All</span></label>
    <label class="td__pill"><input type="radio" name="td-filter" value="todo" data-model="td.filter"><span>To do</span></label>
    <label class="td__pill"><input type="radio" name="td-filter" value="done" data-model="td.filter"><span>Done</span></label>
  </fieldset>

  <ul class="td__list" data-each="td.visible" data-each-key="id">
    <li class="td__item" data-class-done="{done}">
      <label class="td__check">
        <input class="td__box" type="checkbox" data-attr-checked="{done}" data-id="{id}" data-on-change="toggleTask">
        <span class="td__text">{title}</span>
      </label>
      <button class="td__del" type="button" data-id="{id}" data-on-click="removeTask">
        <span aria-hidden="true">&times;</span><span class="td__sr">Delete {title}</span>
      </button>
    </li>
  </ul>

  <p class="td__empty" data-if="td.empty" data-text="td.empty"></p>

  <p class="td__foot" data-if="td.doneCount > 0">
    <button class="td__clear" type="button" data-on-click="clearDone">Clear done</button>
  </p>
</section>

CSS

.td {
  --td-surface: #ffffff;
  --td-ink: #1f1b3a;
  --td-muted: #5a5675;
  --td-line: #dedbee;
  --td-field: #f4f2fc;
  --td-accent: #5a3fd0;
  --td-accent-ink: #ffffff;
  --td-track: #e4e0f6;
  --td-danger: #a6203f;
  --td-ring: #1f1b3a;
  box-sizing: border-box;
  width: min(100%, 26rem);
  padding: 1.25rem;
  color: var(--td-ink);
  background: var(--td-surface);
  border: 1px solid var(--td-line);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgb(31 27 58 / 6%), 0 14px 32px -14px rgb(31 27 58 / 28%);
  font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.td *, .td *::before, .td *::after { box-sizing: border-box; }
.td__sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.td__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.td__eyebrow { margin: 0 0 0.1rem; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--td-muted); }
.td__title { margin: 0; font-size: 1.5rem; line-height: 1.2; }
.td__count { margin: 0; padding: 0.25rem 0.65rem; font-size: 0.85rem; font-weight: 600; color: var(--td-accent); background: var(--td-field); border-radius: 999px; white-space: nowrap; }
.td__progress { display: block; width: 100%; height: 8px; margin: 1rem 0; appearance: none; border: 0; border-radius: 4px; overflow: hidden; background: var(--td-track); color: var(--td-accent); }
.td__progress::-webkit-progress-bar { background: var(--td-track); }
.td__progress::-webkit-progress-value { background: var(--td-accent); transition: width 0.3s ease; }
.td__progress::-moz-progress-bar { background: var(--td-accent); }
.td__form { display: flex; gap: 0.5rem; }
.td__input { flex: 1; width: 100%; min-width: 0; min-height: 44px; padding: 0 0.9rem; font: inherit; color: var(--td-ink); background: var(--td-field); border: 1px solid var(--td-line); border-radius: 12px; }
.td__input::placeholder { color: var(--td-muted); opacity: 1; }
.td__input:focus-visible, .td__add:focus-visible, .td__clear:focus-visible, .td__del:focus-visible, .td__box:focus-visible, .td__pill input:focus-visible { outline: 3px solid var(--td-ring); outline-offset: 2px; }
.td__add { min-height: 44px; padding: 0 1.15rem; font: inherit; font-weight: 700; color: var(--td-accent-ink); background: var(--td-accent); border: 0; border-radius: 12px; cursor: pointer; }
.td__add:hover { filter: brightness(1.1); }
.td__filters { display: flex; gap: 0.4rem; margin: 1rem 0 0.5rem; padding: 0; border: 0; }
.td__pill { position: relative; display: inline-block; }
.td__pill input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; appearance: none; border-radius: 999px; cursor: pointer; }
.td__pill span { position: relative; display: block; padding: 0.35rem 0.9rem; font-size: 0.85rem; font-weight: 600; color: var(--td-muted); border-radius: 999px; pointer-events: none; }
.td__pill input:checked + span { color: var(--td-surface); background: var(--td-ink); }
.td__list { list-style: none; margin: 0; padding: 0; }
.td__item { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; border-bottom: 1px solid var(--td-line); }
.td__check { display: flex; align-items: center; flex: 1; gap: 0.75rem; min-width: 0; min-height: 48px; cursor: pointer; }
.td__box { flex: none; width: 24px; height: 24px; margin: 0; appearance: none; background: var(--td-surface); border: 2px solid var(--td-muted); border-radius: 8px; display: grid; place-items: center; cursor: pointer; }
.td__box::after { content: ""; width: 6px; height: 11px; margin-top: -2px; border: solid var(--td-accent-ink); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) scale(0); transition: transform 0.15s ease; }
.td__box:checked { background: var(--td-accent); border-color: var(--td-accent); }
.td__box:checked::after { transform: rotate(45deg) scale(1); }
.td__text { overflow-wrap: anywhere; }
.td__item.done .td__text { color: var(--td-muted); text-decoration: line-through; text-decoration-thickness: 1.5px; }
.td__del { flex: none; display: grid; place-items: center; width: 44px; height: 44px; font-size: 1.5rem; line-height: 1; color: var(--td-muted); background: transparent; border: 0; border-radius: 12px; cursor: pointer; }
.td__del:hover { color: var(--td-danger); background: var(--td-field); }
.td__empty { margin: 1rem 0 0.25rem; padding: 1.25rem 1rem; text-align: center; color: var(--td-muted); background: var(--td-field); border-radius: 12px; }
.td__foot { margin: 0.75rem 0 0; text-align: right; }
.td__clear { min-height: 44px; padding: 0 0.75rem; font: inherit; font-weight: 600; color: var(--td-accent); background: transparent; border: 0; border-radius: 10px; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
@media (max-width: 24rem) {
  .td { padding: 1rem; }
}
@media (prefers-color-scheme: dark) {
  .td {
    --td-surface: #1b1930; --td-ink: #efedfb; --td-muted: #b4afd1; --td-line: #34305a; --td-field: #25223f;
    --td-accent: #a995ff; --td-accent-ink: #15122b; --td-track: #34305a; --td-danger: #ff8aa5; --td-ring: #efedfb;
    box-shadow: 0 1px 2px rgb(0 0 0 / 35%), 0 16px 34px -14px rgb(0 0 0 / 70%);
  }
}
@media (prefers-reduced-motion: reduce) {
  .td__box::after, .td__progress::-webkit-progress-value { transition: none; }
}

JavaScript

(function () {
  'use strict';
  var td = xon.data('td', {
    draft: '',
    filter: 'all',
    message: '',
    next: 5,
    items: [
      { id: 1, title: 'Sketch the layout', done: true },
      { id: 2, title: 'Reply to the email', done: false },
      { id: 3, title: 'Back up the photos', done: false },
      { id: 4, title: 'Book a haircut', done: true }
    ]
  });

  function countDone(s) { return s.items.filter(function (t) { return t.done; }).length; }

  xon.calc('td.visible', function (s) {
    return s.items.filter(function (t) { return s.filter === 'all' || (s.filter === 'done') === t.done; });
  });
  xon.calc('td.doneCount', countDone);
  xon.calc('td.percent', function (s) { return s.items.length ? Math.round(countDone(s) / s.items.length * 100) : 0; });
  xon.calc('td.status', function (s) {
    if (s.message) return s.message;
    return s.items.length ? countDone(s) + ' of ' + s.items.length + ' done' : 'No tasks';
  });
  xon.calc('td.empty', function (s) {
    var shown = s.items.filter(function (t) { return s.filter === 'all' || (s.filter === 'done') === t.done; });
    if (shown.length) return '';
    return { all: 'No tasks yet. Add one above.', todo: 'Nothing left to do.', done: 'Nothing is done yet.' }[s.filter];
  });

  function addTask(event) {
    event.preventDefault();
    var title = td.draft.trim();
    if (!title) { td.message = 'Type a task first.'; return; }
    td.items = td.items.concat([{ id: td.next++, title: title, done: false }]);
    td.draft = '';
    td.message = '';
  }
  function toggleTask(event, box) {
    var id = Number(box.dataset.id);
    td.items = td.items.map(function (t) { return t.id === id ? { id: t.id, title: t.title, done: box.checked } : t; });
    td.message = '';
  }
  function removeTask(event, button) {
    var id = Number(button.dataset.id), row = button.closest('li');
    var near = row && (row.nextElementSibling || row.previousElementSibling);
    var target = near ? near.querySelector('input') : document.getElementById('td-new');
    td.items = td.items.filter(function (t) { return t.id !== id; });
    td.message = '';
    if (target) target.focus();
  }
  function clearDone() {
    td.items = td.items.filter(function (t) { return !t.done; });
    td.message = '';
    document.getElementById('td-new').focus();
  }
  xon.use(addTask, toggleTask, removeTask, clearDone);
})();

Accessibility notes

Written by the author of the snippet. Each note has a test step or a markup check that reads the page.

  • The count is a status region, so changes are announced.
  • Every task is a native checkbox inside its label, and Space ticks it.
  • Each delete button has a hidden name that includes the task text.
  • After a delete, focus moves to a neighbouring task or the input.