Cinnamon roll · 2026-11-22
CSS accordion with native <details name>
A CSS accordion no longer needs hidden checkboxes, ARIA toggle scripts, or brittle max-height guesses. Link native HTML <details> and <summary> panels with a shared name attribute so opening one closes its siblings automatically, style the body with ::details-content, and layer interpolate-size for smooth height animation.
No checkbox hacks, no max-height guesswork, no accordion script.
Click any drawer in the pure CSS accordion
Every panel below shares name="lab-faq", so opening one drawer automatically closes the others with zero JavaScript. Flip the enhancement toggle to compare smooth interpolate-size sliding against instant snapping.
How does opening one drawer close the others?
Every <details> panel in this stack shares name="lab-faq". The browser treats them like a radio group: opening one panel closes whichever sibling was open before, with zero JavaScript.
Why style ::details-content instead of adding wrapper divs?
The ::details-content pseudo-element targets the expandable body directly. You can control padding, borders, and height animation in CSS while keeping your HTML clean and semantic.
What happens in browsers without interpolate-size?
The smooth height slide is wrapped inside @supports (interpolate-size: allow-keywords). Firefox and Safari skip only the slide and give you an instant, crisp native accordion with zero clipping.
Does this pure CSS accordion work with keyboards?
Yes. Tab moves between <summary> headings, and Enter or Space toggles each drawer. Screen readers also receive the built-in expanded and collapsed state without custom ARIA code.
Smooth height enhancement
Toggle interpolate-size: allow-keywords right here using pure CSS radio buttons — no script touches the page.
This browser supports interpolate-size: allow-keywords — panels slide smoothly to height: auto.
This browser does not support interpolate-size yet — panels use the crisp native snap fallback.
Try pressing Tab and Enter on any summary row: keyboard support and expanded state are built straight into HTML.
Three layers of a modern accordion CSS setup
The core exclusive behavior and styling work across all four major browsers today, while native height animation layers cleanly on top.
01
Exclusive <details name>
Give sibling
<details>tags the samenameattribute and the browser keeps at most one panel open at a time, with no state script.02
Direct ::details-content
Target the collapsible content slot directly in CSS for spacing, transitions, and borders without wrapping every answer in extra markup.
03
Native interpolate-size
Opt into
interpolate-size: allow-keywordsso CSS can transition cleanly betweenblock-size: 0andblock-size: autowithout magic pixel caps.
Copy the HTML details and CSS accordion code
<!-- Shared name makes the accordion exclusive (zero JS) -->
<div class="accordion">
<details name="faq" open>
<summary>How does an exclusive accordion work?</summary>
<p>Panels with the same name close when a sibling opens.</p>
</details>
<details name="faq">
<summary>Do I need ARIA or click scripts?</summary>
<p>No. Native details and summary handle keys and state.</p>
</details>
<details name="faq">
<summary>What if a browser skips the smooth slide?</summary>
<p>It still opens cleanly — animation is an enhancement.</p>
</details>
</div>.accordion details {
border: 2px solid #86e3be;
border-radius: 14px;
background: #1e1033;
color: #fff2de;
overflow: hidden;
}
.accordion summary {
list-style: none;
cursor: pointer;
padding: 1rem 1.2rem;
font-weight: 700;
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary::after { content: "+"; font-family: monospace; }
.accordion details[open] summary::after { content: "−"; }
/* Style the expandable content directly with ::details-content */
.accordion details::details-content {
padding-inline: 1.2rem;
}
.accordion details[open]::details-content {
padding-bottom: 1.1rem;
}/* Smooth height: auto slide (instant fallback elsewhere) */
@media (prefers-reduced-motion: no-preference) {
@supports (interpolate-size: allow-keywords) {
.accordion {
interpolate-size: allow-keywords;
}
.accordion details::details-content {
block-size: 0;
overflow-y: clip;
transition:
block-size 0.3s ease,
content-visibility 0.3s allow-discrete;
}
.accordion details[open]::details-content {
block-size: auto;
}
}
}Browser support (checked 2026-11-22): Exclusive <details name> is Baseline Newly Available since September 2024 across Chrome 120+, Edge 120+, Safari 17.2+, and Firefox 130+ (Web Platform Dashboard: details-name). The ::details-content pseudo-element is Baseline Newly Available since September 2025 across Chrome 131+, Edge 131+, Safari 18.4+, and Firefox 143+ (Web Platform Dashboard: details-content). Smooth interpolate-size: allow-keywords animation is an enhancement supported in Chrome 129+ and Edge 129+ (Safari Technology Preview; not yet in Firefox — Web Platform Dashboard: interpolate-size). Tested in Chromium only.
The fine print, in plain words
Why this is free
We're raccoons who think simple things shouldn't cost a monthly fee. We take techniques apart, explain them in plain words, and give them away. The code on this page is MIT licensed: copy it, change it, and share it.
This is one of twelve experiments so far. Our first browser tool (Bandit Codes) is live now, and the rest sit as ideas in the stash.
Next snack
CSS popover with no JavaScript
Auto vs manual popovers, blurred ::backdrop, and smooth @starting-style transitions.