How to Build an FAQ Accordion with Zero JavaScript

Updated October 2026

By Syed · Frontend Engineer & Creator of UITweak

Almost every accordion tutorial starts the same way: install something, wire up click handlers, manage open state in JavaScript. For an FAQ section, all of that is overhead. Browsers already ship a native accordion in the form of the <details> and <summary> elements. They toggle, they work with keyboards, screen readers understand them, and they need exactly zero JavaScript.

In this guide you will build a polished FAQ accordion with Tailwind CSS: custom icons, one-open-at-a-time mode, and a smooth expand animation. Every step has copy-paste code, and nothing below requires a single line of JavaScript.

Step 1: The markup, details and summary do the work

The structure is three parts. <details> is the container. <summary> is the always-visible header and must be the first child. Everything after it is the collapsible answer. The open attribute controls which item starts expanded.

<div class="w-full max-w-2xl space-y-3">
  <details class="rounded-2xl border border-slate-200 bg-white">
    <summary>What is your refund policy?</summary>
    <p>Full refunds within 30 days, no questions asked.</p>
  </details>

  <details class="rounded-2xl border border-slate-200 bg-white">
    <summary>Do you offer support?</summary>
    <p>Yes, email support with a 24 hour response time.</p>
  </details>
</div>

That alone is a working accordion. Click a question, the answer appears. No event listeners, no state variables, no framework. The browser owns the toggle behavior, which means it also owns the edge cases you would otherwise debug yourself.

Step 2: Style it with Tailwind and swap the marker for a custom icon

The default triangle marker looks dated, so the first styling job is removing it and adding your own icon. Two rules handle every browser: list-none removes the marker in Firefox and Chrome, and [&::-webkit-details-marker]:hidden removes it in Safari.

For the icon, put the group class on <details> and use Tailwind's group-open: variant on the icon. A plus sign that rotates 45 degrees becomes an X, which reads as "close" without any icon library.

<details class="group rounded-2xl border border-slate-200 bg-white">
  <summary class="flex cursor-pointer list-none items-center justify-between p-5 font-semibold [&::-webkit-details-marker]:hidden">
    What is your refund policy?
    <span class="text-2xl leading-none text-slate-400 transition-transform duration-300 group-open:rotate-45">+</span>
  </summary>
  <p class="px-5 pb-5 text-slate-600">Full refunds within 30 days, no questions asked.</p>
</details>

The group-open: variant reacts to the open attribute on the <details> element itself, so the icon rotates exactly when the panel opens. No classes to toggle, because there is nothing toggling them.

Step 3: One open at a time with the name attribute

FAQ accordions usually work in exclusive mode: opening one question closes the others. Traditionally that meant a loop in JavaScript. The name attribute on <details> does it natively. Give every item the same name and the browser groups them.

<details name="faq" class="group rounded-2xl border border-slate-200 bg-white">
  <summary class="flex cursor-pointer list-none items-center justify-between p-5 font-semibold [&::-webkit-details-marker]:hidden">
    What is your refund policy?
    <span class="text-2xl leading-none text-slate-400 transition-transform duration-300 group-open:rotate-45">+</span>
  </summary>
  <p class="px-5 pb-5 text-slate-600">Full refunds within 30 days, no questions asked.</p>
</details>

<details name="faq" class="group rounded-2xl border border-slate-200 bg-white">
  <summary class="flex cursor-pointer list-none items-center justify-between p-5 font-semibold [&::-webkit-details-marker]:hidden">
    Do you offer support?
    <span class="text-2xl leading-none text-slate-400 transition-transform duration-300 group-open:rotate-45">+</span>
  </summary>
  <p class="px-5 pb-5 text-slate-600">Yes, email support with a 24 hour response time.</p>
</details>

That is the entire exclusive-accordion implementation: one shared attribute. It works in all current browsers, and items without a name stay independent, so you can mix grouped and standalone accordions on the same page.

Step 4: Animate the expand without measuring heights

By default the panel snaps open instantly. The reason is that height: auto cannot be transitioned, which is the single most common accordion frustration. The fix that actually works is the grid trick: wrap the answer in a grid container and animate grid-template-rows from 0fr to 1fr. In Tailwind that is all arbitrary values, no custom CSS file needed.

<details class="group rounded-2xl border border-slate-200 bg-white">
  <summary class="flex cursor-pointer list-none items-center justify-between p-5 font-semibold [&::-webkit-details-marker]:hidden">
    What is your refund policy?
    <span class="text-2xl leading-none text-slate-400 transition-transform duration-300 group-open:rotate-45">+</span>
  </summary>
  <div class="grid grid-rows-[0fr] transition-[grid-template-rows] duration-300 ease-out group-open:grid-rows-[1fr]">
    <div class="min-h-0 overflow-hidden">
      <p class="px-5 pb-5 text-slate-600">Full refunds within 30 days, no questions asked.</p>
    </div>
  </div>
</details>

Two details matter here. First, the inner wrapper needs min-h-0 and overflow-hidden, otherwise the content refuses to collapse fully. Second, keep padding on the inner content, not on the animated grid container, or the panel will flicker at the end of the animation.

One honest limitation: the expand animates smoothly, but closing is instant in most browsers because the UA stylesheet hides the content the moment open is removed. That is acceptable progressive enhancement for an FAQ. If you want the full story, including the max-height timing trap and the Chromium-only interpolate-size approach for animating both directions, read our height: auto transition fix guide.

Step 5: Accessibility checklist

The native elements give you most of this for free, but four things are worth checking before you ship:

  • Keyboard works by default. <summary> is focusable and toggles with Enter and Space. Do not add your own key handlers on top of it.
  • Keep summary content simple. The browser strips roles from children of <summary>, so do not nest headings, links, or buttons inside it. Plain text plus your icon span is the safe pattern.
  • Add a visible focus style. Keyboard users need to see which question is focused. A simple focus-visible:outline-2 focus-visible:outline-indigo-500 on the summary covers it.
  • Find-in-page can reveal answers. The content stays in the DOM, and in Chrome (plus Firefox 139 and Safari 26.2 onward) the browser's find-in-page will even open a collapsed <details> to show a match. Most JS accordions built with display: none keep their answers invisible to find.

Mistakes to avoid

  1. Padding on the animated wrapper. The grid trick animates the row, but padding on the outer container sits outside the animation and pops in instantly. Move all padding to the inner content div.
  2. Forgetting the Safari marker rule. list-none alone leaves the default triangle visible in Safari. You need both [&::-webkit-details-marker]:hidden and list-none.
  3. Reaching for JavaScript out of habit. If your accordion only opens, closes, and animates, the native elements do it with less code, fewer bugs, and better accessibility than a hand-rolled script.
  4. Animating max-height with a huge value. A max-height: 999px transition on a 150px answer spends most of its duration animating empty space, which feels laggy. The grid trick animates exactly the content's height instead.

Try it live: grab the finished accordion snippet with a copy button and three live variants from the Accordion gallery element, then come back here when you want to understand how it works.

Fine-tune the motion: open the free CSS Animation Generator, dial in a 300ms ease-out expand for your accordion, and drop the copied cubic-bezier() into the ease-out slot of the grid transition above.

Frequently asked questions

Can I build an accordion with zero JavaScript?

Yes. The native <details> and <summary> HTML elements give you expand and collapse behavior with no scripting. The browser handles the toggle, keyboard interaction, and the open state. You only write CSS for the look.

How do I keep only one FAQ item open at a time without JavaScript?

Give every <details> element the same name attribute, for example name="faq". The browser then treats them as an exclusive group: opening one automatically closes the others. No JavaScript needed, and it works in all modern browsers.

Why won't my accordion animate smoothly?

Because height: auto cannot be transitioned. Wrap the answer in a grid container that animates grid-template-rows from 0fr to 1fr instead. The full breakdown of this and four other fixes is in our height: auto transition guide.

Is a details and summary accordion accessible?

Mostly yes, out of the box. The summary is keyboard operable with Enter and Space, and screen readers announce the expanded state. Keep it that way: do not nest headings or buttons inside <summary>, and add a visible focus style.

Does this work in all browsers?

<details> and <summary> work everywhere modern, including Safari. The name attribute for exclusive mode is supported in all current browsers. The smooth expand animation is progressive enhancement: it animates where supported and still opens and closes everywhere else.

Share this guide