Unread notification filter in HTML, CSS and vanilla JS
A copy-paste Unread notification filter in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="dcl-notifications-unread-filter" data-dcl-scheme="light" aria-label="Unread notification filter example">
<div data-stack>
<div data-row data-spread><h2>Updates</h2><label>Show<select><option value="all">All updates</option><option value="unread">Unread only</option></select></label></div>
<p role="status">Showing 3 updates.</p>
<ul data-stack>
<li data-unread><strong>Unread:</strong> Check the revised cut-off time</li>
<li>Read: Co-owner accepted invitation</li>
<li>Read: Document export completed</li>
</ul>
</div>
<script>
(() => {
const root = document.currentScript.closest(".dcl-notifications-unread-filter");
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 select = find("select");
select.addEventListener("change", () => {
const entries = all("li");
entries.forEach((entry) => { entry.hidden = select.value === "unread" && !entry.hasAttribute("data-unread"); });
const count = entries.filter((entry) => !entry.hidden).length;
find('[role="status"]').textContent = count === 1 ? "Showing 1 update." : "Showing " + count + " updates.";
});
})();
</script>
</section>
<style>
.dcl-notifications-unread-filter, .dcl-notifications-unread-filter * { box-sizing: border-box; }
.dcl-notifications-unread-filter { 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-unread-filter :where(h2, h3, p, ol, ul, dl, dd) { margin: 0; }
.dcl-notifications-unread-filter h2 { font-size: 1.25rem; line-height: 1.25; }
.dcl-notifications-unread-filter h3 { font-size: 1rem; }
.dcl-notifications-unread-filter p + p { margin-block-start: 0.5rem; }
.dcl-notifications-unread-filter [data-stack], .dcl-notifications-unread-filter form { display: grid; gap: 0.75rem; }
.dcl-notifications-unread-filter [data-row] { display: flex; flex-wrap: wrap; gap: 0.5rem 0.75rem; align-items: center; }
.dcl-notifications-unread-filter [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-unread-filter [data-spread] { justify-content: space-between; }
.dcl-notifications-unread-filter [hidden] { display: none !important; }
.dcl-notifications-unread-filter :where(button, summary, input, select) { font: inherit; }
.dcl-notifications-unread-filter :where(button, input, select) { min-block-size: 44px; min-inline-size: 0; max-inline-size: 100%; }
.dcl-notifications-unread-filter :where(button, input, select) { border: 1px solid; border-radius: 0.375rem; padding: 0.45rem 0.7rem; }
.dcl-notifications-unread-filter :where(button, summary) { cursor: pointer; font-weight: 650; }
.dcl-notifications-unread-filter :where(button, summary):active { box-shadow: inset 0 0 0 2px currentColor; }
.dcl-notifications-unread-filter summary:hover { text-decoration: underline; }
.dcl-notifications-unread-filter :where(button, input, select):disabled, .dcl-notifications-unread-filter [aria-disabled=true] { cursor: not-allowed; border-style: dashed; }
.dcl-notifications-unread-filter label { display: grid; gap: 0.25rem; }
.dcl-notifications-unread-filter :where(input, select) { inline-size: 100%; }
.dcl-notifications-unread-filter label[data-choice] { display: flex; gap: 0.5rem; align-items: center; min-block-size: 44px; }
.dcl-notifications-unread-filter label[data-choice] input { inline-size: 1.25rem; block-size: 1.25rem; min-block-size: 0; flex-shrink: 0; }
.dcl-notifications-unread-filter fieldset { min-inline-size: 0; margin: 0; border-radius: 0.375rem; padding: 0.5rem 0.75rem; }
.dcl-notifications-unread-filter :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.dcl-notifications-unread-filter[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.dcl-notifications-unread-filter ul { padding-inline-start: 1.5rem; }
.dcl-notifications-unread-filter { color-scheme: light; border-color: #697f84; }
.dcl-notifications-unread-filter { color: #11292f; background-color: #ffffff; }
.dcl-notifications-unread-filter button, .dcl-notifications-unread-filter input, .dcl-notifications-unread-filter select { color: #11292f; background-color: #e4edef; }
.dcl-notifications-unread-filter button[data-primary] { color: #ffffff; background-color: #00535a; }
.dcl-notifications-unread-filter button:hover { color: #ffffff; background-color: #003c42; }
.dcl-notifications-unread-filter button[disabled], .dcl-notifications-unread-filter button[aria-disabled=true] { color: #405a60; background-color: #e4edef; }
.dcl-notifications-unread-filter[data-dcl-scheme="dark"] { color-scheme: dark; border-color: #839fa5; }
.dcl-notifications-unread-filter[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; }
.dcl-notifications-unread-filter[data-dcl-scheme="dark"] button, .dcl-notifications-unread-filter[data-dcl-scheme="dark"] input, .dcl-notifications-unread-filter[data-dcl-scheme="dark"] select { color: #eff8f9; background-color: #1c3c44; }
.dcl-notifications-unread-filter[data-dcl-scheme="dark"] button[data-primary] { color: #11292f; background-color: #8fe1da; }
.dcl-notifications-unread-filter[data-dcl-scheme="dark"] button:hover { color: #11292f; background-color: #b2f2ec; }
.dcl-notifications-unread-filter[data-dcl-scheme="dark"] button[disabled], .dcl-notifications-unread-filter[data-dcl-scheme="dark"] button[aria-disabled=true] { color: #b0c9ce; background-color: #1c3c44; }
</style>
When to use
Let the person isolate new work without permanently removing entries from the inbox.
Avoid
Do not use unread as a substitute for task priority.
Accessibility
An explicit labeled select filters the list. A persistent status announces the visible item count. Text contrast is at least 6.1:1 in light and 6.7:1 in dark.
Was this useful? Send feedback.