FAQ with a topic picker in HTML, CSS and vanilla JS
A copy-paste FAQ with a topic picker in plain HTML and CSS, with vanilla JavaScript: no framework, no build step, MIT-licensed.
Live preview
Source (copy-ready)
<section class="dcl-faq-section-topic-picker-root" aria-label="FAQ with a topic picker" data-dcl-scheme="light">
<h2>Studio visit questions</h2><p class="dcl-faq-section-topic-picker-muted">Practical answers for visitors to the community archive.</p><div class="dcl-faq-section-topic-picker-bar"><button type="button" data-topic="all" aria-pressed="true">All topics</button>
<button type="button" data-topic="0" aria-pressed="false">Before visiting</button>
<button type="button" data-topic="1" aria-pressed="false">Working in the studio</button>
<button type="button" data-topic="2" aria-pressed="false">After the visit</button></div><p role="status">Showing all topics</p><div class="dcl-faq-section-topic-picker-stack"><div class="dcl-faq-section-topic-picker-stack" data-subject="0"><section class="dcl-faq-section-topic-picker-stack" aria-label="Before visiting"><h3>Before visiting</h3><div class="dcl-faq-section-topic-picker-stack"><details class="dcl-faq-section-topic-picker-disclosure"><summary>Do I need to book?</summary><p>Book a slot if you need time on the scanner.</p></details>
<details class="dcl-faq-section-topic-picker-disclosure"><summary>What should I bring?</summary><p>Bring the papers you want to digitise and a storage drive.</p></details></div></section></div>
<div class="dcl-faq-section-topic-picker-stack" data-subject="1"><section class="dcl-faq-section-topic-picker-stack" aria-label="Working in the studio"><h3>Working in the studio</h3><div class="dcl-faq-section-topic-picker-stack"><details class="dcl-faq-section-topic-picker-disclosure"><summary>Can I bring a guest?</summary><p>One guest can share your booked table.</p></details>
<details class="dcl-faq-section-topic-picker-disclosure"><summary>Is there quiet space?</summary><p>Ask at the desk for the small reading room.</p></details></div></section></div>
<div class="dcl-faq-section-topic-picker-stack" data-subject="2"><section class="dcl-faq-section-topic-picker-stack" aria-label="After the visit"><h3>After the visit</h3><div class="dcl-faq-section-topic-picker-stack"><details class="dcl-faq-section-topic-picker-disclosure"><summary>Are files kept?</summary><p>You take the only copy unless you request a backup.</p></details>
<details class="dcl-faq-section-topic-picker-disclosure"><summary>Can I return a borrowed drive?</summary><p>Return it at the front desk on your next visit.</p></details></div></section></div></div>
<script>
(() => {
const root = document.currentScript.closest(".dcl-faq-section-topic-picker-root");
const preference = matchMedia("(prefers-color-scheme: dark)");
const apply = () => {
root.dataset.dclScheme = document.documentElement.dataset.theme || (preference.matches ? "dark" : "light");
};
preference.addEventListener("change", apply);
apply();
const buttons = [...root.querySelectorAll("[data-topic]")];
buttons.forEach((button) => button.addEventListener("click", () => {
buttons.forEach((item) => item.setAttribute("aria-pressed", String(item === button)));
root.querySelectorAll("[data-subject]").forEach((topic) => {
topic.hidden = button.dataset.topic !== "all" && topic.dataset.subject !== button.dataset.topic;
});
root.querySelector('[role="status"]').textContent = "Showing " + button.textContent;
}));
})();
</script>
</section>
<style>
.dcl-faq-section-topic-picker-root { color: #11292f; background-color: #ffffff; color-scheme: light; }
.dcl-faq-section-topic-picker-root .dcl-faq-section-topic-picker-panel, .dcl-faq-section-topic-picker-root .dcl-faq-section-topic-picker-badge,
.dcl-faq-section-topic-picker-root button, .dcl-faq-section-topic-picker-root input, .dcl-faq-section-topic-picker-root select, .dcl-faq-section-topic-picker-root summary {
color: #11292f; background-color: #e4edef; border-color: #697f84;
}
.dcl-faq-section-topic-picker-root .dcl-faq-section-topic-picker-muted { color: #405a60; }
.dcl-faq-section-topic-picker-root button:hover, .dcl-faq-section-topic-picker-root button[aria-pressed="true"], .dcl-faq-section-topic-picker-root summary:hover {
color: #ffffff; background-color: #00535a;
}
.dcl-faq-section-topic-picker-root a { color: #005c62; }
.dcl-faq-section-topic-picker-root :focus-visible { outline: 3px solid #005c62; outline-offset: 3px; }
.dcl-faq-section-topic-picker-root { --edge: #697f84; --accent: #00535a; }
.dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] { color: #eff8f9; background-color: #142f36; color-scheme: dark; }
.dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] .dcl-faq-section-topic-picker-panel, .dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] .dcl-faq-section-topic-picker-badge,
.dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] button, .dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] input, .dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] select, .dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] summary {
color: #eff8f9; background-color: #1c3c44; border-color: #839fa5;
}
.dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] .dcl-faq-section-topic-picker-muted { color: #b0c9ce; }
.dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] button:hover, .dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] button[aria-pressed="true"], .dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] summary:hover {
color: #11292f; background-color: #8fe1da;
}
.dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] a { color: #8fe1da; }
.dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] :focus-visible { outline: 3px solid #8fe1da; outline-offset: 3px; }
.dcl-faq-section-topic-picker-root[data-dcl-scheme="dark"] { --edge: #839fa5; --accent: #8fe1da; }
.dcl-faq-section-topic-picker-root { display: grid; gap: 1rem; box-sizing: border-box; max-inline-size: 60rem; margin-inline: auto; padding: clamp(0.875rem, 3vw, 2rem);
border: 1px solid var(--edge); border-radius: 0.75rem; font: 1rem/1.55 system-ui, sans-serif; overflow-wrap: anywhere; }
.dcl-faq-section-topic-picker-root * { box-sizing: border-box; min-inline-size: 0; }
.dcl-faq-section-topic-picker-root h2, .dcl-faq-section-topic-picker-root h3, .dcl-faq-section-topic-picker-root p, .dcl-faq-section-topic-picker-root ul, .dcl-faq-section-topic-picker-root ol, .dcl-faq-section-topic-picker-root dl, .dcl-faq-section-topic-picker-root dd, .dcl-faq-section-topic-picker-root figure, .dcl-faq-section-topic-picker-root blockquote, .dcl-faq-section-topic-picker-root fieldset { margin: 0; }
.dcl-faq-section-topic-picker-root h2 { font-size: clamp(1.375rem, 3vw, 2rem); line-height: 1.18; }
.dcl-faq-section-topic-picker-root h3 { font-size: 1.125rem; line-height: 1.3; }
.dcl-faq-section-topic-picker-root ul, .dcl-faq-section-topic-picker-root ol { padding: 0; list-style: none; }
.dcl-faq-section-topic-picker-panel > * + *, .dcl-faq-section-topic-picker-disclosure > * + * { margin-block-start: 0.65rem; }
.dcl-faq-section-topic-picker-stack, .dcl-faq-section-topic-picker-grid, .dcl-faq-section-topic-picker-split, .dcl-faq-section-topic-picker-rail { display: grid; gap: 1rem; align-items: start; }
.dcl-faq-section-topic-picker-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); }
.dcl-faq-section-topic-picker-split { grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
.dcl-faq-section-topic-picker-rail { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.dcl-faq-section-topic-picker-bar { display: flex; flex-wrap: wrap; gap: 0.625rem; align-items: center; }
.dcl-faq-section-topic-picker-spread { justify-content: space-between; }
.dcl-faq-section-topic-picker-panel { padding: 1rem; border: 1px solid var(--edge); border-radius: 0.625rem; }
.dcl-faq-section-topic-picker-badge { display: inline-block; width: fit-content; border: 1px solid var(--edge); border-radius: 1rem;
padding: 0.16rem 0.65rem; font-size: 0.875rem; font-weight: 650; }
.dcl-faq-section-topic-picker-muted { font-size: 0.875rem; }
.dcl-faq-section-topic-picker-root button, .dcl-faq-section-topic-picker-root input, .dcl-faq-section-topic-picker-root select, .dcl-faq-section-topic-picker-root summary {
font: inherit; padding: 0.45rem 0.7rem; border: 1px solid; border-radius: 0.375rem; max-inline-size: 100%; }
.dcl-faq-section-topic-picker-root input[type="checkbox"], .dcl-faq-section-topic-picker-root input[type="radio"] { inline-size: 1.15rem; block-size: 1.15rem; accent-color: var(--accent); }
.dcl-faq-section-topic-picker-root button, .dcl-faq-section-topic-picker-root select, .dcl-faq-section-topic-picker-root summary, .dcl-faq-section-topic-picker-root label { cursor: pointer; }
.dcl-faq-section-topic-picker-root button:disabled { cursor: not-allowed; border-style: dashed; }
.dcl-faq-section-topic-picker-root button:active, .dcl-faq-section-topic-picker-root summary:active { text-decoration: underline; }
.dcl-faq-section-topic-picker-root a { display: inline-block; padding: 0.2rem; text-underline-offset: 0.2em; }
.dcl-faq-section-topic-picker-root a:hover { text-decoration-thickness: 2px; }
.dcl-faq-section-topic-picker-root fieldset { padding: 0.75rem; border: 1px solid var(--edge); border-radius: 0.5rem; }
.dcl-faq-section-topic-picker-root legend { font-weight: 700; padding-inline: 0.35rem; }
.dcl-faq-section-topic-picker-scroll { overflow-x: auto; padding: 0.2rem; }
.dcl-faq-section-topic-picker-root table { border-collapse: collapse; inline-size: 100%; text-align: start; }
.dcl-faq-section-topic-picker-root caption { text-align: start; font-weight: 700; padding-block: 0.375rem; }
.dcl-faq-section-topic-picker-root td, .dcl-faq-section-topic-picker-root th { border-block-end: 1px solid var(--edge); padding: 0.5rem; text-align: start; }
.dcl-faq-section-topic-picker-root svg { display: block; max-inline-size: 100%; block-size: auto; }
.dcl-faq-section-topic-picker-border { border-inline-start: 0.25rem solid var(--accent); padding-inline-start: 0.875rem; }
.dcl-faq-section-topic-picker-center { text-align: center; justify-items: center; }
.dcl-faq-section-topic-picker-center svg { margin-inline: auto; }
.dcl-faq-section-topic-picker-root [hidden] { display: none; }
.dcl-faq-section-topic-picker-stack[hidden], .dcl-faq-section-topic-picker-bar[hidden] { display: none; }
@media (max-width: 34rem) { .dcl-faq-section-topic-picker-rail { grid-template-columns: minmax(0, 1fr); } }
</style>
When to use
Use when each topic has only a few questions and readers should be able to clear a topic filter without losing their place.
Avoid
Do not use filters to conceal an eligibility restriction or required instruction.
Accessibility
Native buttons expose their pressed state. The current filter is announced, and native disclosures remain independently keyboard operable. Theme token text pairs reach at least 6.2:1 in light and 6.8:1 in dark.
Was this useful? Send feedback.