Skip to content

Accordion with details and summary

No-JavaScript FAQ accordion built on native details and summary elements with smooth height animation and one-open-at-a-time behavior.

Also known as: faq accordion, collapsible faq, expandable questions, details summary accordion

Accordion with details and summary live demo

Open in new tab

Pure CSS code (HTML, CSS)

A FAQ accordion built only with HTML and CSS, using the native details and summary elements. Items open with a smooth height animation, the plus icon turns into a minus, and only one answer is open at a time, all without a single line of JavaScript. Use it for FAQ pages, help centers, pricing page questions or product spec sheets.

How it works

The root section.acd-faq is a grid with an .acd-intro column (kicker, heading and lead text) and an .acd-list of details.acd-item elements. Each item has a summary.acd-summary containing the .acd-question text and a decorative .acd-icon, followed by an .acd-panel with the answer.

The browser handles opening and closing: clicking the summary, or pressing Enter or Space on it, toggles the open attribute. All items share name="acd-faq", which turns them into an exclusive group, so opening one closes the others. The default triangle is hidden with ::-webkit-details-marker and ::marker.

The animation has two layers. In browsers that support the ::details-content pseudo-element, .acd-item::details-content animates block-size from 0 to auto, which works because .acd-faq sets interpolate-size: allow-keywords; the content-visibility transition with allow-discrete keeps the content visible until the closing animation ends. In every browser, the acd-reveal keyframes fade and slide the .acd-panel in when an item opens. The .acd-icon is drawn from two pseudo-element bars; when the item is [open] the vertical bar rotates flat, the circle fills with the accent color and spins half a turn. From 900px the intro and list sit side by side and the intro stays sticky while you scroll long lists.

Customization

  • --acd-accent on .acd-faq: color of the kicker, open border, icon and focus ring.
  • --acd-accent-soft: background of the icon circle on closed items.
  • --acd-speed: duration of the height, icon and fade animations.
  • --acd-radius: corner radius of each item and its focus outline.
  • --acd-bg, --acd-item-bg and --acd-border: section background, item background and resting border color.
  • Remove the name="acd-faq" attribute from the details elements to let several answers stay open at once.
  • Remove open from the first details to start with every item closed.
  • grid-template-columns in the 900px media query: the width ratio of the intro and question columns.

Use cases

  • FAQ pages: answers expand with a smooth animation and only one stays open at a time
  • Help centers: native details and summary elements work without any JavaScript
  • Pricing pages: common billing questions sit in a compact list under the plans
  • Product spec sheets: a plus icon turning into a minus shows which item is open

Accessibility

Native details and summary elements come with built-in semantics: screen readers announce each summary as an expandable control with its expanded or collapsed state, and keyboard users can Tab between questions and toggle them with Enter or Space. The .acd-icon is aria-hidden, so only the question text is read. A clear outline appears on .acd-summary:focus-visible. With prefers-reduced-motion: reduce, the height transition, the fade-in and the icon rotation are all turned off, and items open instantly.

Usage notes

Browsers without ::details-content or interpolate-size still open and close items normally and show the fade-in, just without the height animation. The exclusive name grouping is supported in all current browsers; older ones simply allow several open items. Give each accordion on a page its own name value so groups do not affect each other.

Accordion with details and summary at a glance

Framework
Pure CSS
Code
HTML, CSS
JavaScript
Not needed, CSS only
Dependencies
None
Layout
Responsive, works on mobile
Category
Accordions
License
Free for personal and commercial use

Questions about this template

Can I use the Accordion with details and summary code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

There is nothing to install. Paste the HTML where the component should appear and add the CSS to your stylesheet. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. It is built with HTML and CSS only, so there is no JavaScript to load.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

No dependencies. Pure HTML, CSS and JavaScript.

Accordion with details and summary – free Pure CSS accordion template
Accordion with details and summary · free Pure CSS accordion template

More Accordions

Horizontal Image Accordion – free Pure CSS accordion template

Horizontal Image Accordion

Row of five photo panels that expand horizontally on hover, focus or tap, with vertical titles, smooth @property transitions and a stacked mobile layout.

Accordion with Icons – free Bootstrap 5 accordion template

Accordion with Icons

Bootstrap 5 FAQ accordion with leading icon tiles, subtitles, rounded cards, a rotating plus icon and a warm accent color.

Plus/Minus Accordion – free Tailwind CSS accordion template

Plus/Minus Accordion

Tailwind CSS accordion with a rotating plus/minus icon, smooth height animation, keyboard navigation and a switch for single-open or multi-open mode.