Component Library

← Back to gallery

Select-and-archive notifications in HTML, CSS and vanilla JS

A copy-paste Select-and-archive notifications in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.

Category: Feedback · Tags: notifications, inbox, updates, status

Live preview

Source (copy-ready)

<section class="dcl-notifications-batch-archive" data-dcl-scheme="light" aria-label="Select-and-archive notifications example">
<div data-stack>
  <h2>Clear older notifications</h2>
  <fieldset><legend>Select messages</legend>
    <label data-choice><input type="checkbox">Archived checklist due date</label>
    <label data-choice><input type="checkbox">October export finished</label>
    <label data-choice><input type="checkbox">Workspace visit scheduled</label>
  </fieldset>
  <div data-row><button type="button" data-archive>Archive selected</button><button type="button" data-undo disabled>Undo archive</button></div>
  <p role="status"></p>
</div>
<script>
(() => {
  const root = document.currentScript.closest(".dcl-notifications-batch-archive");
  const preference = matchMedia("(prefers-color-scheme: dark)");
  const setTheme = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
  preference.addEventListener("change", setTheme);
  setTheme();
  const find = (selector) => root.querySelector(selector);
  const all = (selector) => Array.from(root.querySelectorAll(selector));
  const undo = find("[data-undo]");
  const archive = find("[data-archive]");
  const result = find('[role="status"]');
  const group = find("fieldset");
  let last = [];
  archive.addEventListener("click", () => {
    const selected = all("input").filter((item) => !item.parentElement.hidden && item.checked);
    if (!selected.length) { result.textContent = "Select at least one notification."; return; }
    last = selected;
    selected.forEach((item) => { item.checked = false; item.parentElement.hidden = true; });
    group.hidden = all("label").every((label) => label.hidden);
    undo.disabled = false;
    result.textContent = "Archived " + last.length + " selected notification(s).";
  });
  undo.addEventListener("click", () => {
    last.forEach((item) => { item.parentElement.hidden = false; });
    group.hidden = false;
    result.textContent = "Restored " + last.length + " notification(s).";
    last = [];
    archive.focus();
    undo.disabled = true;
  });
})();
</script>
</section>
<style>
.dcl-notifications-batch-archive, .dcl-notifications-batch-archive * { box-sizing: border-box; }
.dcl-notifications-batch-archive { font: 1rem/1.5 system-ui, sans-serif; max-inline-size: 40rem; padding: clamp(0.75rem, 3vw, 1.25rem); border: 1px solid; border-radius: 0.75rem; overflow-wrap: anywhere; }
.dcl-notifications-batch-archive :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-notifications-batch-archive h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-notifications-batch-archive h3 { font-size: 1rem; }
.dcl-notifications-batch-archive p + p { margin-block-start: 0.5rem; }
.dcl-notifications-batch-archive [data-stack], .dcl-notifications-batch-archive form { display: grid; gap: 0.75rem; }
.dcl-notifications-batch-archive [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-notifications-batch-archive [data-split] { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 1.25rem; align-items: start; }
.dcl-notifications-batch-archive [data-spread] { justify-content: space-between; }
.dcl-notifications-batch-archive [hidden] { display: none !important; }
.dcl-notifications-batch-archive :where(button, summary, input, select) { font: inherit; }
.dcl-notifications-batch-archive :where(button, input, select) { min-block-size: 44px; min-inline-size: 0; max-inline-size: 100%; }
.dcl-notifications-batch-archive :where(button, input, select) { border: 1px solid; border-radius: 0.375rem; padding: 0.45rem 0.7rem; }
.dcl-notifications-batch-archive :where(button, summary) { cursor: pointer; font-weight: 650; }
.dcl-notifications-batch-archive :where(button, summary):active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-notifications-batch-archive summary:hover { text-decoration: underline; }
.dcl-notifications-batch-archive :where(button, input, select):disabled, .dcl-notifications-batch-archive [aria-disabled=true] { cursor: not-allowed; border-style: dashed; }
.dcl-notifications-batch-archive label { display: grid; gap: 0.25rem; }
.dcl-notifications-batch-archive :where(input, select) { inline-size: 100%; }
.dcl-notifications-batch-archive label[data-choice] { display: flex; gap: 0.5rem; align-items: center; min-block-size: 44px; }
.dcl-notifications-batch-archive label[data-choice] input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; flex-shrink: 0; }
.dcl-notifications-batch-archive fieldset { min-inline-size: 0; margin: 0; border-radius: 0.375rem; padding: 0.5rem 0.75rem; }
.dcl-notifications-batch-archive :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-notifications-batch-archive[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-notifications-batch-archive { color-scheme: light; border-color: #697f84; }
.dcl-notifications-batch-archive { color: #11292f; background-color: #ffffff; }
.dcl-notifications-batch-archive button, .dcl-notifications-batch-archive input, .dcl-notifications-batch-archive select { color: #11292f; background-color: #e4edef; }
.dcl-notifications-batch-archive button[data-primary] { color: #ffffff; background-color: #00535a; }
.dcl-notifications-batch-archive button:hover { color: #ffffff; background-color: #003c42; }
.dcl-notifications-batch-archive button[disabled], .dcl-notifications-batch-archive button[aria-disabled=true] { color: #405a60; background-color: #e4edef; }
.dcl-notifications-batch-archive[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-notifications-batch-archive[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-notifications-batch-archive[data-dcl-scheme="dark"] button, .dcl-notifications-batch-archive[data-dcl-scheme="dark"] input, .dcl-notifications-batch-archive[data-dcl-scheme="dark"] select { color: #eff8f9; background-color: #1c3c44; }
.dcl-notifications-batch-archive[data-dcl-scheme="dark"] button[data-primary] { color: #11292f; background-color: #8fe1da; }
.dcl-notifications-batch-archive[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #b2f2ec; }
.dcl-notifications-batch-archive[data-dcl-scheme="dark"] button[disabled], .dcl-notifications-batch-archive[data-dcl-scheme="dark"] button[aria-disabled=true] { color: #b0c9ce; background-color: #1c3c44; }
</style>

When to use

Support bulk cleanup for a frequently used notification inbox.

Avoid

Do not silently archive other messages when no checkboxes are selected.

Accessibility

Wrapped labels identify each checkbox. The live status reports the selection outcome and an undo button restores the last archived batch. Text contrast is at least 6.1:1 in light and 6.7:1 in dark.

Was this useful? Send feedback.