Build a zero-JavaScript FAQ accordion using native <details> and <summary> elements, with a shared name attribute for exclusive single-open groups. Add smooth height transitions in Chromium via ::details-content and @supports (interpolate-size: allow-keywords), while keeping instant toggle fallbacks, proper <section aria-labelledby> grouping, and clean <summary> semantics across all browsers.
HTML Details and Summary: Build an Accessible, Animated FAQ Accordion Without JavaScript
Build a zero-JS FAQ accordion with HTML details and summary. Covers name groups, ::details-content animation, CSS fallbacks, find-in-page, and A11y limits.
// The short answer
In this guide · 10 sections
- 01Semantic FAQ Markup and the open Attribute
- 02Exclusive Accordion Groups with the name Attribute
- 03Styling the Marker and Rotating a Custom Icon
- 04Animating Open and Close with ::details-content and interpolate-size
- 05Listening to State Changes with the toggle Event
- 06Find-in-Page Behavior and Closed Content
- 07Accessibility Limits of <details> and <summary>
- 08Decision Rule: <details> vs. button + aria-expanded vs. hidden="until-found"
- 09Copy-Paste Production HTML and CSS Snippet
- 10Failure Modes and Verification Checklist
Swapping out a JavaScript accordion or a third-party collapsible package for native <details> and <summary> elements lets you cut state-syncing code, trim your bundle size, and hand keyboard and screen-reader behavior straight to the browser. You get exclusive single-open groups through the HTML name attribute and smooth height transitions in Chromium browsers via ::details-content and interpolate-size, while other engines fall back to an instant toggle without breaking semantics.
Prerequisites: Vanilla HTML and CSS. You don't need build tools, preprocessors, or JavaScript frameworks.
JavaScript cost:
0 KBfor the core toggle, exclusive grouping, and animation.Core
<details>/<summary>support: Baseline Widely Available across Chrome, Edge, Firefox, and Safari.Exclusive
nameattribute: Chrome/Edge 120+, Firefox 130+, Safari 17.2+ (older browsers simply let multiple panels stay open at once).Height animation (
::details-content+interpolate-size): Modern Chrome, Edge, Firefox, and Safari all support::details-contentandtransition-behavior: allow-discrete, whileinterpolate-size: allow-keywordsis Chromium-only (Chrome/Edge 129+); Firefox and Safari fall back to an instant open and close.
Semantic FAQ Markup and the open Attribute
A native disclosure widget only needs two elements: <details> as the state container and <summary> as its first child. Anything you put inside <details> after <summary> becomes the collapsible panel.
<section class="faq" aria-labelledby="faq-heading">
<h2 id="faq-heading">Frequently Asked Questions</h2>
<details class="faq-item" open>
<summary class="faq-trigger">
<span>Does this accordion require JavaScript?</span>
<span class="faq-icon" aria-hidden="true"></span>
</summary>
<div class="faq-panel">
<p>No. The browser manages the open state, keyboard activation, and screen-reader announcements natively.</p>
</div>
</details>
<details class="faq-item">
<summary class="faq-trigger">
<span>Can I use custom markup inside the answer panel?</span>
<span class="faq-icon" aria-hidden="true"></span>
</summary>
<div class="faq-panel">
<p>Yes. Any flow content (paragraphs, lists, code blocks, or tables) works inside the panel wrapper.</p>
</div>
</details>
</section>Two parser rules will trip you up right away if you miss them:
<summary>must be the first child of<details>. Drop a<div>or heading ahead of<summary>and the HTML parser treats your<summary>like plain content, sticks a default "Details" toggle at the top, and wrecks your layout.openis a boolean attribute. Addingopenexpands the item on initial load. Writingopen="false"still renders the item open because the browser only checks whether the attribute is there at all. To close it programmatically, strip the attribute (element.removeAttribute("open")orelement.open = false).
Exclusive Accordion Groups with the name Attribute
Want only one FAQ item open at a time? Give every <details> element in the group the exact same name attribute. Opening one item automatically closes any open sibling sharing that name, giving you radio-button exclusivity without writing an event listener.
<section class="faq" aria-labelledby="billing-faq">
<h2 id="billing-faq">Billing</h2>
<details class="faq-item" name="billing-group" open>
<summary class="faq-trigger">
<span>How are invoices delivered?</span>
<span class="faq-icon" aria-hidden="true"></span>
</summary>
<div class="faq-panel">
<p>PDF invoices are emailed automatically on the first day of each billing cycle.</p>
</div>
</details>
<details class="faq-item" name="billing-group">
<summary class="faq-trigger">
<span>Can I switch plans mid-cycle?</span>
<span class="faq-icon" aria-hidden="true"></span>
</summary>
<div class="faq-panel">
<p>Upgrades apply immediately with prorated billing; downgrades take effect on the next renewal date.</p>
</div>
</details>
</section>When a page has two separate FAQ sections, give each section its own name value (like billing-group and shipping-group) so opening an item in one section doesn't collapse the other.
Exclusivity works in Chrome and Edge 120+, Firefox 130+, and Safari 17.2+. Older versions simply ignore the name attribute and let multiple panels stay open at once, and nothing breaks.
Before you add name, think through the UX trade-off. Mutual exclusion saves vertical space on long pages, yet it stops readers from comparing two answers side by side. For technical docs or pricing breakdowns where people cross-reference answers, leave name off so panels stay independent.
Styling the Marker and Rotating a Custom Icon
Browsers draw the default disclosure triangle in two different ways: Chromium and Firefox attach a ::marker pseudo-element to display: list-item, while older WebKit/Safari builds use ::-webkit-details-marker. Hide both so you start from the same baseline across every engine.
.faq-trigger {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 1rem 1.25rem;
font-weight: 600;
cursor: pointer;
list-style: none;
}
.faq-trigger::-webkit-details-marker {
display: none;
}
.faq-trigger:focus-visible {
outline: 2px solid #2563eb;
outline-offset: -2px;
border-radius: 0.5rem;
}Once you strip out the default triangle, give users a clear visual cue so they know the control expands. Don't drop raw text characters like + or v straight into the DOM where screen readers might read them aloud; use an aria-hidden="true" element or a CSS border chevron instead.
.faq-icon {
width: 0.65rem;
height: 0.65rem;
flex-shrink: 0;
border-right: 2px solid currentColor;
border-bottom: 2px solid currentColor;
transform: rotate(45deg);
transition: transform 0.2s ease;
}
.faq-item[open] .faq-icon {
transform: rotate(-135deg);
}Leave :focus-visible alone. Replacing the native marker or turning <summary> into a flex container won't break keyboard focusability, and stripping the focus ring hides where keyboard users are on the page.
Animating Open and Close with ::details-content and interpolate-size
For years, you couldn't animate <details> height in pure CSS because hidden content jumped straight between content-visibility: hidden and content-visibility: visible, and CSS couldn't transition from 0 to auto. Three modern features fix this:
::details-content: Targets the anonymous slot holding everything inside<details>except<summary>.transition-behavior: allow-discrete: Holds off on switchingcontent-visibilitytohiddenuntil your closing transition finishes.interpolate-size: allow-keywords: Lets the browser animateblock-size(orheight) smoothly between0andauto.
Wrap those animation rules inside @supports and @media (prefers-reduced-motion: no-preference) so unsupported browsers and folks who turn off motion get a clean, instant toggle with zero layout glitches.
@media (prefers-reduced-motion: no-preference) {
@supports (interpolate-size: allow-keywords) {
.faq-item {
interpolate-size: allow-keywords;
}
.faq-item::details-content {
block-size: 0;
opacity: 0;
overflow: clip;
transition:
block-size 0.28s ease,
opacity 0.28s ease,
content-visibility 0.28s allow-discrete;
}
.faq-item[open]::details-content {
block-size: auto;
opacity: 1;
}
}
}Compatibility and Fallback Strategy
Current Chrome, Edge, Firefox, and Safari all support ::details-content and transition-behavior: allow-discrete, whereas interpolate-size: allow-keywords is still Chromium-only (Chrome/Edge 129+). Because the animation block sits behind @supports (interpolate-size: allow-keywords), Firefox and Safari skip the height transition and pop the panel open or closed right away.
Resist the temptation to swap <details> for a hidden <input type="checkbox"> and a grid-template-rows: 0fr to 1fr trick just to get sliding everywhere. That checkbox hack wipes out native disclosure semantics, forces you to wire up focus and aria-expanded by hand, and breaks find-in-page auto-expansion. Treating the slide animation as progressive enhancement keeps your markup standard and your accessibility intact.
Listening to State Changes with the toggle Event
When you need side effects, like logging which FAQ items users open, syncing the active item to a URL hash, or wiring up an "Expand all / Collapse all" button, listen for the native toggle event rather than click on <summary>. The toggle event fires right after the browser updates the open state, whether a user clicked, hit a key, triggered a name group close, or matched text with find-in-page.
document.querySelectorAll(".faq-item").forEach((item) => {
item.addEventListener("toggle", (event) => {
const triggerText = item.querySelector("summary")?.textContent?.trim();
if (event.newState === "open") {
// Example: send analytics or update UI state
console.log("Opened:", triggerText);
}
});
});event.newState and event.oldState give you "open" or "closed". Since the browser stays the single source of truth for the open attribute, your script never drifts out of sync with the DOM.
Find-in-Page Behavior and Closed Content
In Chromium browsers (Chrome and Edge), hitting Ctrl+F or Cmd+F and searching for text inside a collapsed <details> panel automatically expands that <details> element and scrolls straight to the match. If the item belongs to a name group, opening it through find-in-page also closes the previously open sibling.
Firefox and Safari don't reliably auto-expand closed <details> panels during find-in-page searches. Because discoverability differs across engines, and plenty of readers scan instead of searching, so never tuck critical form validation errors, legal terms needed at checkout, or mandatory setup steps inside a collapsed <details> panel by default.
Accessibility Limits of <details> and <summary>
Native <details> handles the essentials out of the box: <summary> is keyboard-focusable, fires on Enter or Space, and reports its expanded or collapsed state to assistive technology. Still, it has hard limits that will bite you if you ignore them.
Disclosure Widget vs. WAI-ARIA Accordion
<details> is a disclosure widget, not a full WAI-ARIA accordion. It doesn't give you arrow-key navigation between headers (ArrowDown / ArrowUp / Home / End), and it won't create a landmark region on its own.
Don't add role="button" or aria-expanded to <summary>. The browser already maps <summary> to a disclosure button role and tracks its expanded state natively; tacking those attributes on creates duplicate or conflicting screen-reader announcements.
Headings and Interactive Elements Inside <summary>
Because <summary> carries an implicit button role, screen readers treat everything inside it as presentational text. Putting an <h3> inside <summary> causes many screen-reader and browser pairings to strip the heading role, knocking it out of the document outline and heading-navigation shortcuts. Keep your section headings outside <details> and stick to plain text (or <span>) inside <summary>.
Never drop interactive elements like <a href>, <button>, or <input> inside <summary>. Clicking or hitting Enter on a nested interactive control creates messy event conflicts where a link might navigate at the same time it toggles the panel, and screen readers can't reliably expose nested controls inside a button.
Group Labelling
Wrap related <details> items inside a <section> tied to a visible heading with aria-labelledby:
<section class="faq" aria-labelledby="faq-heading">
<h2 id="faq-heading">Frequently Asked Questions</h2>
<!-- <details> items -->
</section>That gives screen-reader users a clear landmark and heading structure without messing up <summary> semantics.
Decision Rule: <details> vs. button + aria-expanded vs. hidden="until-found"
Pick the primitive based on the interaction contract your UI actually needs, not on which snippet looks shortest.
| Requirement | <details> + <summary> |
<button aria-expanded> + Panel |
hidden="until-found" + Button |
|---|---|---|---|
| JavaScript required | None (0 KB) |
Required for toggle & state sync | Required for toggle & beforematch |
Headings as triggers (<h3><button>) |
Not reliable (button role strips heading) | Full support | Full support |
| Interactive controls in header | Not supported | Supported (sibling to button) | Supported (sibling to button) |
Exclusive group (name) |
Native (Chrome 120, FF 130, Safari 17.2) |
Manual JS | Manual JS |
| Cross-browser height animation | Chromium-only via interpolate-size |
Full control (CSS Grid or WAAPI) | Full control (JS + CSS) |
| Find-in-page auto-reveal | Chromium only | No (if display: none or hidden) |
Chromium & Firefox (via beforematch) |
Rule of thumb:
Use
<details>+<summary>for FAQs, optional technical notes, and progressive disclosures where plain-text triggers and a Chromium-only slide animation (with an instant fallback) work fine.Use
<button aria-expanded>inside a heading (<h3><button>) when your accordion headers belong in the page's heading hierarchy, when headers need secondary action buttons or links, or when your design calls for identical height animations across Chrome, Firefox, and Safari.Use
hidden="until-found"when you're already building a custom JS-driven collapsible section or tab panel and want browser find-in-page and fragment URLs (#section-id) to reveal collapsed content automatically through thebeforematchevent.
Copy-Paste Production HTML and CSS Snippet
Drop this HTML and CSS straight into any static page or component template without extra build steps or naming collisions. Remove the name="faq-group" attribute if you want multiple panels to stay open at the same time.
<section class="faq" aria-labelledby="faq-title">
<h2 id="faq-title" class="faq-heading">Frequently Asked Questions</h2>
<details class="faq-item" name="faq-group" open>
<summary class="faq-trigger">
<span>How do exclusive accordion groups work without JavaScript?</span>
<span class="faq-icon" aria-hidden="true"></span>
</summary>
<div class="faq-panel">
<p>Assign the same <code>name</code> attribute to every <code><details></code> element in the group. Opening one item automatically closes any other open item sharing that name.</p>
</div>
</details>
<details class="faq-item" name="faq-group">
<summary class="faq-trigger">
<span>What happens in browsers that do not support interpolate-size?</span>
<span class="faq-icon" aria-hidden="true"></span>
</summary>
<div class="faq-panel">
<p>The height animation is scoped inside <code>@supports (interpolate-size: allow-keywords)</code>. Browsers without support skip the transition and open or close the panel instantly.</p>
</div>
</details>
<details class="faq-item" name="faq-group">
<summary class="faq-trigger">
<span>Can I put links or headings inside the summary tag?</span>
<span class="faq-icon" aria-hidden="true"></span>
</summary>
<div class="faq-panel">
<p>Keep headings outside <code><details></code> and avoid interactive controls inside <code><summary></code>. Place links and rich markup inside the answer panel instead.</p>
</div>
</details>
</section>.faq {
max-width: 46rem;
margin-inline: auto;
display: grid;
gap: 0.75rem;
}
.faq-heading {
margin: 0 0 0.5rem;
font-size: 1.5rem;
line-height: 1.3;
}
.faq-item {
border: 1px solid #d4d4d8;
border-radius: 0.5rem;
background-color: #ffffff;
color: #18181b;
}
.faq-trigger {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding: 1rem 1.25rem;
font-weight: 600;
line-height: 1.4;
cursor: pointer;
list-style: none;
user-select: none;
}
.faq-trigger::-webkit-details-marker {
display: none;
}
.faq-trigger:focus-visible {
outline: 2px solid #2563eb;
outline-offset: -2px;
border-radius: 0.5rem;
}
.faq-icon {
width: 0.6rem;
height: 0.6rem;
flex-shrink: 0;
border-right: 2px solid currentColor;
border-bottom: 2px solid currentColor;
transform: rotate(45deg);
transition: transform 0.2s ease;
}
.faq-item[open] .faq-icon {
transform: rotate(-135deg);
}
.faq-panel {
padding: 0 1.25rem 1rem;
color: #3f3f46;
line-height: 1.6;
}
.faq-panel > :first-child {
margin-top: 0;
}
.faq-panel > :last-child {
margin-bottom: 0;
}
@media (prefers-reduced-motion: no-preference) {
@supports (interpolate-size: allow-keywords) {
.faq-item {
interpolate-size: allow-keywords;
}
.faq-item::details-content {
block-size: 0;
opacity: 0;
overflow: clip;
transition:
block-size 0.28s ease,
opacity 0.28s ease,
content-visibility 0.28s allow-discrete;
}
.faq-item[open]::details-content {
block-size: auto;
opacity: 1;
}
}
}
@media (prefers-reduced-motion: reduce) {
.faq-icon {
transition: none;
}
}Failure Modes and Verification Checklist
Most broken <details> setups come down to five common mistakes:
Visible strip when closed: Putting
paddingdirectly on::details-contentinstead of an inner.faq-panelwrapper stops the closed panel from collapsing all the way to0px. Always put vertical padding on the inner wrapper.Text overflowing during animation: Leaving
overflow: clip(oroverflow: hidden) off::details-contentlets panel text spill past the border whileblock-sizeanimates.Double markers in Safari: Setting
list-style: nonewithoutsummary::-webkit-details-marker { display: none; }leaves the default triangle sitting right next to your custom chevron in older WebKit builds.Stuck-open panels from
open="false": Templating engines that output boolean attributes as strings (open="false") keep the panel expanded. Leave the attribute out completely when closed.Broken toggle when
<summary>is not first: Slipping a decorative wrapper or icon ahead of<summary>inside<details>forces the browser to generate a fallback "Details" label.
Before you ship, run through these four quick checks in your browser:
Keyboard test: Hit
Tabto move across each.faq-trigger. Make sure the:focus-visiblering shows up clearly, then pressEnterandSpaceto check open/close behavior and exclusivenameswitching.Reduced-motion test: Open DevTools, turn on
prefers-reduced-motion: reducein the Rendering panel, and toggle a few items. Both the panel height and the chevron rotation should snap immediately with zero animation.Find-in-page test: Collapse an item in Chrome or Edge, press
Ctrl+F/Cmd+F, and search for a word inside its.faq-panel. Confirm the panel pops open automatically and highlights the match.Accessibility tree check: Inspect
<summary>in the DevTools Accessibility tab. Make sure it exposes a disclosure/button role with anexpandedstate and doesn't have duplicatearia-expandedattributes or nested interactive roles.
Quick answers
Frequently asked questions
How do I make only one HTML details element open at a time without JavaScript?
Give every details element in the FAQ group the exact same name attribute. Once you click or activate one item, Chrome and Edge 120+, Firefox 130+, and Safari 17.2+ automatically close any other open item sharing that name. Older browsers simply ignore the attribute and allow multiple panels to stay open at once.
Can I animate HTML details and summary height with pure CSS?
Yes, you can animate the panel height from 0 to auto by pairing the ::details-content pseudo-element with transition-behavior: allow-discrete and interpolate-size: allow-keywords. Since only Chromium browsers support interpolate-size right now, wrap the transition inside @supports (interpolate-size: allow-keywords) so Firefox and Safari fall back cleanly to an instant toggle.
How do I remove or replace the default disclosure triangle on a summary tag?
Set list-style: none on your summary element, then add a summary::-webkit-details-marker { display: none; } rule to catch older WebKit browsers. Once the built-in triangle is gone, drop in an aria-hidden visual cue like a rotated border chevron and keep a clear :focus-visible outline for anyone navigating by keyboard.
Why does my HTML details element stay open when I set open="false"?
Because open is a boolean HTML attribute, the browser treats it as true the moment it sees the attribute in your tag, no matter what string value you pass. To keep a details panel closed by default, leave the open attribute out of your markup entirely or strip it in JavaScript with removeAttribute('open').
Should I put heading tags or links inside an HTML summary element?
No, keep headings and interactive controls outside the summary tag. Because summary carries an implicit button role, screen readers often strip heading semantics from nested h2 or h3 tags, and dropping links or buttons inside summary creates conflicting click and keyboard behavior.
Do I need to add role="button" or aria-expanded to summary for accessibility?
No, the browser already maps summary to a disclosure button role and reports its expanded or collapsed state to assistive tech natively. Adding role="button" or toggling aria-expanded yourself only duplicates those semantics and can trigger redundant or conflicting screen-reader announcements.
Does browser find-in-page search work inside closed HTML details elements?
In Chromium browsers like Chrome and Edge, hitting Ctrl+F or Cmd+F automatically pops open a closed details panel and scrolls to the match whenever text turns up inside. Firefox and Safari don't reliably auto-expand closed details panels during find-in-page searches, so avoid hiding essential instructions or error messages inside collapsed items.
When should I use button with aria-expanded instead of HTML details and summary?
Reach for a button with aria-expanded inside a heading when your accordion triggers need to show up in the page outline, hold secondary links or actions, or run identical height animations across Chrome, Firefox, and Safari. Stick with native details and summary whenever plain-text triggers and progressive enhancement fit your needs with zero JavaScript.
Something wrong or out of date?
Tools change fast. Tell the editor what no longer works.