You’ve been there before. It’s late on a Thursday, and a “simple” UI ticket lands on your desk: build a FAQ section. On the surface, an accordion is the Hello World of interactive components. You click a header, the panel slides open, and the user gets their answer. But as you start coding, the questions start piling up like unwashed coffee mugs. Should the first item be open by default? Does a screen reader actually tell the user that the content just appeared? And why, in the year 2024, is animating a transition from height: 0 to height: auto still a nightmare that causes layout jank?

\\n\\n

The frustration isn’t just yours; it’s a systemic gap in how we teach front-end engineering. We focus so much on the “look” that we ignore the “feel” and the “function.” When an accordion is built poorly, it’s not just a minor visual glitch. For a user navigating via a screen reader, a missing aria-expanded attribute makes the component a literal dead end. For a user on a low-end mobile device, a heavy JavaScript-based height calculation can make the whole page stutter. We aren’t just building toggles; we are building gateways to information. If those gateways are heavy, clunky, or invisible to assistive technology, we’ve failed our users.

\\n\\n
\\nDirect Practical Verdict:\\n

The gold-standard accordion uses a semantic <button> nested inside a heading tag, controlled by aria-expanded. For high-performance, jank-free animations, abandon JavaScript height calculations in favor of the CSS Grid grid-template-rows: 0fr/1fr transition. This approach ensures full accessibility compliance while maintaining 60fps visual smoothness without layout recalculation penalties.

\\n
\\n\\n

Why do most developers fail the “Simple Accordion” test?

\\n\\n

The “Costly Trap” in accordion development is the over-reliance on generic <div> tags and manual state management that ignores the browser’s built-in accessibility tree. I see it in almost every audit I perform: a developer uses a <div> with a click listener, styles it to look like a header, and calls it a day. To a sighted user with a mouse, it works. To everyone else, it’s broken.

\\n\\n

When you use a <div> instead of a <button>, you lose keyboard focusability for free. You lose the “Enter” and “Space” key triggers. You lose the ability for a screen reader to announce “Button, collapsed.” You are then forced to write “polyfilling” JavaScript to put those features back in—features that the browser would have given you for zero lines of code if you’d just used the right tag. This isn’t just an elitist preference for semantic HTML; it’s about reducing the surface area for bugs. The more custom code you write to mimic native behavior, the more likely you are to ship a regression.

\\n\\n

Then there is the animation trap. For years, we’ve been told you can’t animate to height: auto. This led to a decade of developers hard-coding max-height: 1000px, which creates a weird delay in the animation if the content is short, or cuts off the content if it’s long. Or worse, we use Element.scrollHeight in a requestAnimationFrame loop, which forces the browser to recalculate the layout of the entire page every single frame. On a complex page, that’s a recipe for a sluggish UI that feels “cheap.”

\\n\\n
\\n\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n
Implementation MethodAccessibility ScoreAnimation PerformanceMaintenance OverheadBest For…
Native <details>High (Native)Poor (Hard to animate)ZeroSimple disclosures, no-JS environments.
Div + JS ClickZero/FailVariableHigh (Manual ARIA)Nothing. Avoid this at all costs.
ARIA Button + Max-HeightHighMediocre (Timing issues)LowLegacy browser support (IE11).
ARIA Button + CSS GridGold StandardExcellent (60fps)LowModern production web apps.
\\n
\\n\\n

How do you structure the ARIA states for a professional accordion?

\\n\\n

Let’s talk about the anatomy of a professional accordion. It starts with the relationship between the trigger and the panel. You cannot simply have a button and a div floating near each other; they must be programmatically linked. This is where aria-controls and aria-expanded come into play.

\\n\\n

The trigger must be a <button>. Inside that button, you put your label (e.g., “What is your return policy?”). This button should be wrapped in a heading tag (<h2>, <h3>, etc.) that fits the document hierarchy. Why? Because screen reader users often navigate pages by jumping from heading to heading. If your accordion triggers aren’t headings, you’ve just made your FAQ section invisible to a significant portion of your audience.

\\n\\n

The aria-expanded attribute is the star of the show. It’s a boolean: true when the panel is visible, false when it’s hidden. When this state changes, the screen reader immediately notifies the user. Without it, the user clicks the button, nothing seems to happen (from their perspective), and they are left wondering if the site is broken. Additionally, use aria-controls="panel-id" on the button to point to the id of the content panel. While support for aria-controls is inconsistent across all screen readers, it remains the “gold standard” for defining that relationship explicitly.

\\n\\n

Can you really animate height: auto with just CSS?

\\n\\n

For years, the answer was “no,” or at least “not without a hack.” But the modern solution is remarkably elegant: CSS Grid. By using grid-template-rows, we can transition between 0fr (zero fractional units) and 1fr (one fractional unit).

\\n\\n

Here is the secret sauce: You wrap your content in a container that has display: grid. You set the grid-template-rows to 0fr by default and add a transition property to that specific attribute. Inside that grid container, you have a single child <div> with min-height: 0 and overflow: hidden. When the accordion opens, you toggle a class that changes the parent to grid-template-rows: 1fr. The browser handles the interpolation perfectly, animating from exactly zero to exactly the intrinsic height of the content. No JavaScript calculations, no layout thrashing, just pure, hardware-accelerated CSS.

\\n\\n

This approach solves the “content jumping” issue. Because the grid is calculating the fractional space, it doesn’t matter if your content is two lines or twenty paragraphs; the animation timing remains consistent and the browser doesn’t have to guess the final height before it starts moving. It is, quite frankly, the most significant “quality of life” improvement for UI developers in recent years.

\\n\\n

Should you allow multiple accordion panels to be open at once?

\\n\\n

This is a UX debate that often gets heated, but the answer depends entirely on the user’s intent. In a “Disclosure” pattern (like a single “Show More” button), there is only one panel. In an “Accordion” pattern (a list of items), you have two choices: “Single-Expand” (opening one closes the others) or “Multi-Expand” (items stay open until manually closed).

\\n\\n

Single-Expand is best for structured data where the user is looking for one specific answer, such as a FAQ or a settings page. It keeps the page short and reduces visual noise. However, it can be frustrating if the user needs to compare information between two panels. If you are building a product comparison tool or a complex technical manual, Multi-Expand is the superior choice. It respects the user’s agency and prevents the “pogo-sticking” effect where they have to keep re-opening panels they just closed.

\\n\\n

From an accessibility standpoint, if you use the Single-Expand pattern, ensure that the focus stays on the button the user just clicked. Never move the focus automatically unless the user’s action explicitly requires it (like opening a modal). If closing one panel causes the page to shift significantly, the user needs to maintain their “anchor” on the trigger they are currently interacting with.

\\n\\n

The Actionable Playbook: Building the Gold-Standard Accordion

\\n\\n

Follow these steps to implement a production-ready accordion by 4:00 PM today. This workflow prioritizes accessibility first, performance second, and aesthetics third.

\\n\\n
    \\n
  1. Establish the Semantic Skeleton: Wrap your accordion in a container. Each item should consist of a heading (e.g., <h3>) containing a <button>. Immediately following the heading, place your content <div>.
  2. \\n
  3. Wire the ARIA Attributes: Give the button a unique id and set aria-expanded="false". Give the content panel a matching id and set role="region" and aria-labelledby="button-id". This creates a two-way programmatic link.
  4. \\n
  5. Implement the CSS Grid Wrapper: \\n \n
    \n
    \n CODE\n
    \n
    CODE
    \\n.accordion-panel {\\n  display: grid;\\n  grid-template-rows: 0fr;\\n  transition: grid-template-rows 300ms ease-out;\\n}\\n.accordion-panel[aria-hidden="false"] {\\n  grid-template-rows: 1fr;\\n}\\n.accordion-content {\\n  overflow: hidden;\\n  min-height: 0;\\n}\\n
    \n
    \n\\n
  6. \\n
  7. Write the Toggle Logic: Use a simple JavaScript event listener on the button. When clicked, toggle the aria-expanded attribute between true and false. If you are using the Single-Expand pattern, find all other buttons in the group and set their aria-expanded to false.
  8. \\n
  9. Handle Keyboard Navigation: Ensure that the “Tab” key moves focus through the buttons in order. Since you used semantic <button> tags, the “Enter” and “Space” keys will work automatically. Do not override these native behaviors.
  10. \\n
  11. Add Visual Cues: Use a CSS transition on an icon (like a chevron) inside the button. Rotate it 180 degrees when aria-expanded="true". This provides a clear non-textual cue that the state has changed.
  12. \\n
\\n\\n

Frequently Asked Questions

\\n\\n

Can I use the native <details> and <summary> tags instead?

\\n

Yes, for simple disclosures where animation isn’t a priority. However, <details> is notoriously difficult to animate smoothly across all browsers without hacky workarounds. For a “premium” feel with custom transitions, the ARIA-button + CSS Grid approach is superior.

\\n\\n

Does aria-controls actually do anything for screen readers?

\\n

In some screen readers (like JAWS), aria-controls allows users to jump directly from the trigger to the controlled element using a shortcut key. While not all screen readers support it yet, including it is a “future-proof” best practice that adds no overhead.

\\n\\n

How do I handle nested accordions?

\\n

Nested accordions are generally a sign of information architecture failure. However, if you must use them, ensure each level has a distinct heading level (e.g., H3 for the parent, H4 for the child) so the user understands the hierarchy through the screen reader’s heading list.

\\n\\n\\n\\n\\n\\n
\\nExplore Accessible Component Architecture & Disclosure UX\\n

For tactical frontend component implementations and ARIA state management, review our deep dive on Multi-Brand Design Tokens: Style Dictionary Architecture.

\\n
\\n\\n