Removable applied filter chips in HTML, CSS and vanilla JS
A copy-paste Removable applied filter chips in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="example-filter-chips-removable" data-dcl-scheme="light" aria-labelledby="example-filter-chips-removable-title">
<header><h2 id="example-filter-chips-removable-title">Removable applied filter chips</h2>
<p>Applied filters stay visible as chips that can be removed individually or cleared together.</p></header>
<div class="parts">
<div class="panel" data-note>
<h3>Applied filters</h3>
<div class="inline-row chip-row" data-chip-list>
<button type="button" class="chip" data-chip aria-label="Remove status filter Open"><span>Status: Open</span><span aria-hidden="true">×</span></button>
<button type="button" class="chip" data-chip aria-label="Remove owner filter Design"><span>Owner: Design</span><span aria-hidden="true">×</span></button>
<button type="button" class="chip" data-chip aria-label="Remove date filter This month"><span>Date: This month</span><span aria-hidden="true">×</span></button>
</div>
<p class="empty-message" data-empty hidden>No filters applied; every result is visible.</p>
<div class="actions"><button type="button" data-clear>Clear all filters</button></div>
</div>
<p class="status" role="status" aria-live="polite" data-status></p>
</div>
<script>
(() => {
const root = document.currentScript.closest(".example-filter-chips-removable");
const instance = Array.from(document.getElementsByClassName("example-filter-chips-removable")).indexOf(root);
if (instance > 0) {
const singleReferences = ["id", "aria-activedescendant", "for", "list", "name"];
const tokenReferences = ["aria-labelledby", "aria-controls", "aria-describedby"];
for (const element of [root, ...root.querySelectorAll("*")]) {
for (const attr of singleReferences) {
if (element.hasAttribute(attr)) element.setAttribute(attr, element.getAttribute(attr) + "--" + instance);
}
for (const attr of tokenReferences) {
if (element.hasAttribute(attr)) {
const rewritten = element.getAttribute(attr).trim().split(/\s+/).filter(Boolean).map((reference) => reference + "--" + instance);
element.setAttribute(attr, rewritten.join(" "));
}
}
const href = element.getAttribute("href");
if (href && href.startsWith("#")) element.setAttribute("href", href + "--" + instance);
}
}
const preference = matchMedia("(prefers-color-scheme: dark)");
const apply = () => { root.dataset.dclScheme = preference.matches ? "dark" : "light"; };
preference.addEventListener("change", apply);
apply();
const list = root.querySelector("[data-chip-list]");
const clear = root.querySelector("[data-clear]");
const empty = root.querySelector("[data-empty]");
const status = root.querySelector("[data-status]");
function sync(message) {
const count = list.querySelectorAll("[data-chip]").length;
empty.hidden = count !== 0;
clear.disabled = count === 0;
status.textContent = message || count + " filter" + (count === 1 ? "" : "s") + " applied.";
}
list.addEventListener("click", (event) => {
const chip = event.target.closest("[data-chip]");
if (!chip) return;
const label = chip.textContent.replace("×", "").trim();
chip.remove();
sync(label + " removed.");
});
clear.addEventListener("click", () => {
list.replaceChildren();
sync("All filters cleared.");
});
sync();
})();
</script></section>
<style>
.example-filter-chips-removable { color: #11292f; background-color: #ffffff; color-scheme: light; }
.example-filter-chips-removable a { color: #005c62; }
.example-filter-chips-removable button, .example-filter-chips-removable summary, .example-filter-chips-removable input, .example-filter-chips-removable select, .example-filter-chips-removable textarea {
color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.example-filter-chips-removable button:hover, .example-filter-chips-removable summary:hover, .example-filter-chips-removable button[aria-selected="true"], .example-filter-chips-removable button[aria-pressed="true"] {
color: #ffffff; background-color: #00535a;
}
.example-filter-chips-removable dialog { color: #11292f; background-color: #ffffff; }
.example-filter-chips-removable [data-note] { color: #11292f; background-color: #e4edef; }
.example-filter-chips-removable [data-error] { color: #7f1d1d; background-color: #fee2e2; }
.example-filter-chips-removable [data-success] { color: #14532d; background-color: #dcfce7; }
.example-filter-chips-removable [data-warning] { color: #713f12; background-color: #fef9c3; }
.example-filter-chips-removable :focus-visible { outline: 3px solid #005c62; outline-offset: 2px; }
.example-filter-chips-removable[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.example-filter-chips-removable[data-dcl-scheme="dark"] a { color: #8fe1da; }
.example-filter-chips-removable[data-dcl-scheme="dark"] button, .example-filter-chips-removable[data-dcl-scheme="dark"] summary,
.example-filter-chips-removable[data-dcl-scheme="dark"] input, .example-filter-chips-removable[data-dcl-scheme="dark"] select, .example-filter-chips-removable[data-dcl-scheme="dark"] textarea {
color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.example-filter-chips-removable[data-dcl-scheme="dark"] button:hover, .example-filter-chips-removable[data-dcl-scheme="dark"] summary:hover,
.example-filter-chips-removable[data-dcl-scheme="dark"] button[aria-selected="true"], .example-filter-chips-removable[data-dcl-scheme="dark"] button[aria-pressed="true"] {
color: #11292f; background-color: #8fe1da;
}
.example-filter-chips-removable[data-dcl-scheme="dark"] dialog { color: #eff8f9; background-color: #142f36; }
.example-filter-chips-removable[data-dcl-scheme="dark"] [data-note] { color: #eff8f9; background-color: #1c3c44; }
.example-filter-chips-removable[data-dcl-scheme="dark"] [data-error] { color: #fecaca; background-color: #451a1a; }
.example-filter-chips-removable[data-dcl-scheme="dark"] [data-success] { color: #bbf7d0; background-color: #14532d; }
.example-filter-chips-removable[data-dcl-scheme="dark"] [data-warning] { color: #fde68a; background-color: #451a03; }
.example-filter-chips-removable[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 2px; }
.example-filter-chips-removable, .example-filter-chips-removable * { box-sizing: border-box; min-width: 0; }
.example-filter-chips-removable { display: block; font: 1rem/1.5 system-ui, sans-serif; padding: 1rem; border-radius: 0.75rem; overflow-wrap: anywhere; }
.example-filter-chips-removable h2, .example-filter-chips-removable h3 { line-height: 1.15; margin-block: 0 0.75rem; }
.example-filter-chips-removable header p, .example-filter-chips-removable p { margin-block: 0.5rem; }
.example-filter-chips-removable ul, .example-filter-chips-removable ol { margin-block: 0.5rem; padding-inline-start: 1.5rem; }
.example-filter-chips-removable dl { margin-block: 0.5rem; }
.example-filter-chips-removable dt { font-weight: 700; }
.example-filter-chips-removable dd { margin: 0 0 0.6rem; }
.example-filter-chips-removable fieldset { min-inline-size: 0; margin: 0; border: 1px solid; border-radius: 0.5rem; padding: 0.75rem; }
.example-filter-chips-removable legend { padding-inline: 0.25rem; font-weight: 700; }
.example-filter-chips-removable button, .example-filter-chips-removable input, .example-filter-chips-removable select, .example-filter-chips-removable textarea {
min-block-size: 44px; border: 1px solid; border-radius: 0.375rem; padding: 0.5rem 0.75rem; font: inherit;
}
.example-filter-chips-removable input, .example-filter-chips-removable select, .example-filter-chips-removable textarea { display: block; inline-size: 100%; max-inline-size: 100%; }
.example-filter-chips-removable input[type="checkbox"], .example-filter-chips-removable input[type="radio"] {
display: inline-block; inline-size: auto; min-block-size: auto; padding: 0; flex: 0 0 auto;
}
.example-filter-chips-removable input[type="file"] { padding: 0.45rem; }
.example-filter-chips-removable input[type="range"] { padding-inline: 0; }
.example-filter-chips-removable textarea { min-block-size: 6rem; resize: vertical; }
.example-filter-chips-removable button, .example-filter-chips-removable summary { cursor: pointer; transition: background-color 140ms ease-out; }
.example-filter-chips-removable button:disabled { cursor: not-allowed; text-decoration: line-through; }
.example-filter-chips-removable table { border-collapse: collapse; inline-size: 100%; }
.example-filter-chips-removable th, .example-filter-chips-removable td { padding: 0.5rem; text-align: start; border-block-end: 1px solid; }
.example-filter-chips-removable [hidden] { display: none !important; }
.example-filter-chips-removable [data-note], .example-filter-chips-removable [data-error], .example-filter-chips-removable [data-success], .example-filter-chips-removable [data-warning] { border-radius: 0.5rem; padding: 0.65rem; }
.example-filter-chips-removable .parts { display: grid; gap: 1rem; }
.example-filter-chips-removable .field, .example-filter-chips-removable .fields { display: grid; gap: 0.4rem; }
.example-filter-chips-removable .fields { gap: 0.75rem; }
.example-filter-chips-removable .actions, .example-filter-chips-removable .inline-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.example-filter-chips-removable .panel { border: 1px solid; border-radius: 0.5rem; padding: 0.75rem; }
.example-filter-chips-removable .plain-list { margin: 0; padding: 0; list-style: none; }
.example-filter-chips-removable .choice { display: flex; gap: 0.5rem; align-items: flex-start; }
.example-filter-chips-removable .choice input { margin-block-start: 0.25rem; }
.example-filter-chips-removable .choice-stack { display: grid; gap: 0.55rem; }
.example-filter-chips-removable .tile { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.55rem; align-items: start; border: 1px solid; border-radius: 0.5rem; padding: 0.75rem; }
.example-filter-chips-removable .tile[data-active] { border-width: 3px; padding: calc(0.75rem - 2px); }
.example-filter-chips-removable .pill { display: inline-flex; gap: 0.4rem; align-items: center; border: 1px solid; border-radius: 999px; padding: 0.35rem 0.7rem; }
.example-filter-chips-removable .pill[data-active] { border-width: 3px; padding: calc(0.35rem - 2px) calc(0.7rem - 2px); }
.example-filter-chips-removable .hint { font-size: 0.875rem; }
.example-filter-chips-removable .status { min-block-size: 1.5rem; margin-block: 0; }
.example-filter-chips-removable .two-column, .example-filter-chips-removable .split-layout { display: grid; gap: 1rem; }
.example-filter-chips-removable .sticky-panel { position: sticky; inset-block-start: 1rem; align-self: start; }
.example-filter-chips-removable .scroll-x { overflow-x: auto; max-inline-size: 100%; }
.example-filter-chips-removable .visually-hidden {
position: absolute; inline-size: 1px; block-size: 1px; padding: 0; margin: -1px;
overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
@media (min-width: 34rem) {
.example-filter-chips-removable .two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.example-filter-chips-removable .split-layout { grid-template-columns: minmax(0, 1fr) minmax(12rem, 18rem); }
}
@media (max-width: 30rem) {
.example-filter-chips-removable { padding: 0.75rem; }
.example-filter-chips-removable .actions, .example-filter-chips-removable .inline-row { align-items: stretch; }
.example-filter-chips-removable .wizard-steps { grid-template-columns: minmax(0, 1fr) !important; }
}
@media (prefers-reduced-motion: reduce) { .example-filter-chips-removable * { transition: none !important; } }
.example-filter-chips-removable .empty-message[hidden] { display: none !important; }
.example-filter-chips-removable .chip { display: inline-flex; gap: 0.4rem; align-items: center; border-radius: 999px; }
.example-filter-chips-removable .empty-message { margin-block-end: 0.75rem; }
</style>
When to use
Use this when filters are applied from another panel and people need a compact receipt of what is limiting the results. Keep every removal explicit and leave Clear all disabled once nothing remains.
Avoid
Do not use removable chips as the only way to add filters; they represent existing state rather than replacing the filter controls themselves.
Accessibility
Each removal is a native button whose accessible name names the filter, Clear all is disabled when empty, and the remaining count is announced politely. Meaning is carried by text, not the chip colour. Main text contrast is 15.19:1 light and 13.07:1 dark; controls are 12.78:1 and 10.94:1.
Was this useful? Send feedback.