Details Summary Accordion With Smooth Open
An order and care FAQ for a small pottery studio, built on the native details and summary elements so every question opens with no script. Where the browser supports interpolate-size and the ::details-content pseudo-element, the answer slides open to its natural height; older browsers open it instantly. On phones the rows keep a 56 pixel tap height and long questions wrap beside the chevron.
Code
// Native <details> and <summary>: works with no script. Smooth height where the browser supports interpolate-size.
const items = [
{ q: "How long does a hand-thrown mug take to reach me?", a: "Every mug is thrown, dried for a week and fired twice, so allow three to four weeks from order to doorstep. We email a photo when yours comes out of the kiln." },
{ q: "Are the glazes safe for food and the dishwasher?", a: "Yes. All of our glazes are lead free and fired to stoneware temperature. They go in the dishwasher and microwave, though hand washing keeps the matte finishes looking new for longer." },
{ q: "Can I order a set in a colour that is not listed?", a: "Sets of six or more can be glazed in any of our test colours. Write to the studio with the shade you have in mind and we will send a sample tile first." },
{ q: "What happens if a piece arrives broken?", a: "Send us a photo within seven days and we will make a replacement in the next firing. You do not need to return the broken piece." },
];
export default function DetailsSummaryAccordionWithSmoothOpenCss() {
return (
<section className="dsa bg-stone-100 px-5 py-16 sm:py-20">
<style>{`
.dsa details { interpolate-size: allow-keywords; }
.dsa details::details-content { block-size: 0; overflow: hidden; transition: block-size .35s cubic-bezier(.2,.7,.2,1), content-visibility .35s allow-discrete; }
.dsa details[open]::details-content { block-size: auto; }
.dsa summary { list-style: none; }
.dsa summary::-webkit-details-marker { display: none; }
.dsa .dsa-chev { transition: transform .3s cubic-bezier(.2,.7,.2,1); }
.dsa details[open] .dsa-chev { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) {
.dsa details::details-content, .dsa .dsa-chev { transition: none; }
}
`}</style>
<div className="mx-auto max-w-2xl">
<p className="text-xs font-semibold uppercase tracking-[0.2em] text-amber-800">Saltmarsh Pottery</p>
<h2 className="mt-2 text-2xl font-semibold tracking-tight text-stone-900 sm:text-3xl">Orders and care</h2>
<div className="mt-8 divide-y divide-stone-300 border-y border-stone-300">
{items.map((it, i) => (
<details key={it.q} open={i === 0}>
<summary className="flex min-h-[56px] cursor-pointer items-center justify-between gap-4 py-4 text-left text-base font-medium text-stone-900 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-amber-700 focus-visible:ring-offset-2 focus-visible:ring-offset-stone-100">
{it.q}
<svg className="dsa-chev h-5 w-5 shrink-0 text-stone-500" viewBox="0 0 20 20" fill="none" stroke="currentColor" strokeWidth="1.8" aria-hidden="true"><path d="M5 7.5l5 5 5-5" strokeLinecap="round" strokeLinejoin="round" /></svg>
</summary>
<p className="pb-5 pr-8 text-[15px] leading-relaxed text-stone-600">{it.a}</p>
</details>
))}
</div>
</div>
</section>
);
}
Install with one command: npx shadcn@latest add https://we.inc/r/details-summary-accordion-with-smooth-open-css.json
When to use it
- A shop or service page needs a short list of questions and you want it to work before any script has loaded.
- Your site is plain HTML or a static generator, and adding a component library for one FAQ block would be overkill.
- You want the browser's find-in-page to reach text hidden inside closed answers, which native details elements allow in Chrome.
- The content team edits the FAQ in a CMS that outputs raw HTML, so the markup has to stay simple to paste.
How to customize it
- Change --dsa-speed from .35s to tune how fast a panel slides; anything above half a second starts to feel slow.
- Add the same name attribute (for example name="care") to every details element to make the list close one panel when another opens.
- Swap --dsa-accent for your brand colour; it only drives the focus outline, so keep it dark enough to see on the background.
- Remove the open attribute from the first details element if you would rather the list load fully closed.
Accessibility
- The summary element is a real disclosure control, so keyboards open it with Enter or Space and screen readers announce expanded or collapsed without any ARIA.
- The default triangle marker is hidden and replaced by a decorative chevron marked aria-hidden; the question text remains the accessible name.
- A visible focus outline sits around the whole question row, so keep it if you restyle the summary.
Questions
How do I animate the height of a details element?
Set interpolate-size: allow-keywords on the details element, then transition block-size on its ::details-content pseudo-element between 0 and auto. Add content-visibility to the transition with allow-discrete so the closing slide plays before the content is hidden.
What do browsers without interpolate-size do?
They ignore the unknown property and the panel opens at full height in one step. Nothing breaks and no content is lost, which is why this method needs no fallback script.
Can only one panel be open at a time without JavaScript?
Yes. Give every details element in the group the same name attribute. Current Chrome, Edge, Safari and Firefox then close the open one when you open another, exactly like radio buttons.
Is details and summary good for SEO?
Search engines read the text inside closed details elements, so the answers are indexed. If the block is a real FAQ you can also add FAQPage structured data that repeats the same questions and answers.
Why hide the default marker?
The built-in triangle looks different in every browser and cannot be animated well. Setting list-style: none on the summary and hiding the webkit marker lets you draw one consistent icon.
Related: Accordion Collection with Styled details and summary, ARIA and React, plus FAQ Schema, Single-Open React Accordion With aria-controls, FAQ Accordion With Plus Minus Icon.
More faq and accordions or all free UI components. Build your site free to have a full site built around it.
More in Faq
- FAQ Accordion in React Beside an Opal Glass Globe Lamp in WebGL That Glows Brighter as Each Answer Opens
- Folded Paper Tag FAQ Hung on Brass Hooks in Ray Marched Sunlight Where Each Tag Drops Open to Show Its Printed Answer
- Matchbook FAQ Row Where Each Printed Cover Flips up off Its Comb of Matches to Show the Answer Inside
- Oak Card Index Box FAQ with Tabbed Question Cards That Rise out and Stand Against the Open Lid
- Accordion Collection with Styled details and summary, ARIA and React, plus FAQ Schema
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App