Native HTML Accordions: details, name, and CSS

Native HTML Accordions: details, name, and CSS

An accordion component is five jobs bundled together, and each one is now native. Exclusive groups without JavaScript, animated panels (height only in Chromium-based browsers, as of November 2026), and find-in-page that opens the right panel.

An accordion component is five jobs bundled together — open/close state, disclosure semantics, exclusivity, animation, and deep-linking — and every one of them now has a native answer, with height animation limited to Chromium-based browsers such as Chrome and Edge as of November 2026. details and summary have carried state and semantics across all core browsers since January 2020; the name attribute added exclusivity; ::details-content made the collapsible region stylable and transitionable, and animating its height to auto also needs interpolate-size. This article walks the inventory piece by piece, with a working exclusive accordion, an animated open/close, the find-in-page behavior script-driven accordions have had to work around, and the honest cases where a component is still the correct answer.

What the JS accordion component actually did

It helps to itemize the thing before replacing it. A typical accordion — hand-rolled or pulled from a UI library — is doing five separable jobs, and they arrived in the codebase at different times for different reasons.

The first is state: something has to remember which panels are open, and something has to flip that state on click and on Enter or Space. The second is semantics: aria-expanded on the trigger, aria-controls pointing at the panel, a role on each, and the bookkeeping to keep the attribute in step with the visual state. The third is exclusivity — the close-the-others behavior — which is usually where the component's actual logic lives. The fourth is animation, because collapsing to zero height without a transition looks broken. The fifth, when anyone bothered, is deep-linking: opening the right panel when a URL fragment points inside it.

Each of those was a source of per-library variance, and the ARIA layer in particular was a source of quiet bugs — an aria-expanded that stopped matching reality after a programmatic close is invisible in the design review and completely visible to a screen reader user.

The disclosure element covers the first two outright. State lives in one attribute, keyboard toggling comes from the engine, and the disclosure semantics are built in — nothing to wire, nothing to keep in sync. What changed more recently is that the remaining three are also native now: exclusivity through an attribute, animation through a pseudo-element plus interpolate-size for height (only Chromium-based browsers such as Chrome and Edge, as of November 2026), and searchability through the engine's own find-in-page. That is what turns "we could use details for simple cases" into a component retirement.

The disclosure primitive

The anatomy is minimal. A details element wraps its content; the first child summary becomes the visible label and the toggle. The presence or absence of the open attribute is the state — the whole state, inspectable in browser developer tools and settable in markup. The element fires a toggle event when it changes, which is the hook an integration listens to when it needs to react to the change.

details and summary have been available across browsers since January 2020, which puts them comfortably in Baseline Widely available territory (MDN, accessed November 2026). For the element itself there is no support conversation left to have.

Styling starts with the disclosure marker. In Chrome, Edge and Firefox the default triangle is a ::marker on the summary, and it is removable or replaceable there. In Safari the triangle is controlled through the non-standard ::-webkit-details-marker pseudo-element, and Safari's ::marker support is limited to color and font size (as of November 2026, MDN browser-compat-data), so the reset needs both. The other half of the job is making the whole row a hit target rather than just the text, and giving the summary a focus treatment, since the HTML Standard suggests, subject to platform conventions, that browsers make it focusable and reachable in sequential (Tab) navigation.

css
summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  cursor: pointer;
  list-style: none; /* ::marker exists only on display: list-item, so display: flex already drops it; this covers a list-item reset (Chrome, Edge, Firefox) */
}

summary::-webkit-details-marker {
  display: none; /* Safari */
}

summary:focus-visible {
  outline: 2px solid var(--color-focus);
  outline-offset: -2px;
}

Two structural habits are worth adopting early. Put a heading element inside the summary when the panels are document sections, so the heading structure is in the markup — the summary is the interactive control, the heading is the outline entry. The HTML Standard allows headings in a summary, but MDN warns that some browsers still give the summary a button role, which removes the roles of its children, so the heading may not be exposed as a heading to screen reader users; test the result on multiple platforms. And treat a group of sibling details elements as the accordion; there is no wrapper component required, which is precisely the point.

Exclusive accordions with name

The name attribute groups disclosure elements the way a shared name groups radio buttons: opening one closes the others in its group. No listener, no state container, no component.

html
<div class="accordion">
  <details name="shipping" open>
    <summary>Standard delivery</summary>
    <div class="panel">Arrives in three to five business days.</div>
  </details>

  <details name="shipping">
    <summary>Express delivery</summary>
    <div class="panel">Arrives the next business day when ordered before noon.</div>
  </details>

  <details name="shipping">
    <summary>Collect in store</summary>
    <div class="panel">Ready within two hours at participating locations.</div>
  </details>
</div>

Two design decisions are encoded in that markup rather than in configuration. All-closed is a permitted state — closing the open panel leaves the group empty, unlike a radio group, which suits an accordion whose panels are all optional reading. And the initial state is just the open attribute on whichever panel should start expanded; put it on none and the group opens closed.

What this deletes is the part of the component that was actually complicated: the handler that received a toggle, walked the sibling set, closed the others, and guarded against the recursive toggles its own writes produced. That logic is gone, along with the timing bugs that lived in it.

The exclusivity behavior reached Baseline Newly available in September 2024, when Firefox 130 became the last of the core browsers to ship it; Chrome 120 and Safari 17.2 had it from December 2023 (Web Platform Features Explorer, accessed November 2026). Engines that do not know the attribute ignore it, which degrades to a group of independent disclosures — a designed state, and usually an acceptable one.

One accessibility caveat is worth carrying: the exclusive behavior means a panel can close because the user opened a different one, and you should not assume that transition is announced to screen reader users — test it with the screen readers your audience uses. If the group's content is long enough that a user could be reading inside a panel when it collapses, keep the panels short or reconsider exclusivity.

Styling and animating open/close

The collapsible region used to be unstylable. It is not a child you can select — it is a slot inside the element's built-in shadow tree that holds everything except the first summary. ::details-content is the hook that finally addresses it, and together with interpolate-size, which only Chromium-based browsers such as Chrome and Edge support as of November 2026, the open/close transition stops requiring a measured wrapper element.

css
:root {
  interpolate-size: allow-keywords; /* Chromium-based browsers only, as of November 2026 */
}

details::details-content {
  block-size: 0;
  overflow: hidden;
  transition:
    block-size 0.3s ease,
    content-visibility 0.3s allow-discrete;
}

details[open]::details-content {
  block-size: auto;
}

Those rules compose two capabilities this topic covers separately, and both are load-bearing here. Animating to an intrinsic size — the interpolate-size: allow-keywords line — is what makes block-size: auto a transitionable endpoint rather than a jump; without it the panel snaps, which as of November 2026 is what Firefox and Safari do (MDN browser-compat-data). And the discrete-property transition is what keeps the content rendered for the duration of the collapse instead of vanishing on the first frame. Each has its own treatment; this is the composition, not the explanation.

The overflow: hidden is not decoration. Without it the content spills out of the animating box during the transition, which is one reason a first attempt can look wrong.

There is a rendering angle worth knowing on the closed side. Closed panels have their content skipped, so a page with fifty collapsed disclosures does not pay full layout and paint for fifty hidden regions. That is a meaningful difference from a hand-rolled accordion that keeps everything in the tree with a height of zero. Skipped is not the same as removed, though: the content stays findable, which is the next section.

::details-content reached Baseline Newly available in September 2025 (MDN, accessed November 2026), which makes it the newest piece of the three and the one most likely to need a support gate in your project. Browsers without it do not animate, and neither, as of November 2026, do Firefox and Safari, which support it but lack interpolate-size: panels snap open and closed, and everything still works.

Deep linking, search, and support posture

Here is the capability script-driven accordions have had to work around. When a user runs the browser's own find-in-page, or lands on a URL whose fragment points at an element inside a closed panel, supporting browsers expand that panel automatically and scroll to the match. As of November 2026, MDN browser-compat-data records that Safari 26.2 and later expands the panel on find-in-page but does not correctly scroll to the matching text. Content inside a closed disclosure is part of the page as far as the browser is concerned.

The contrast is stark. A component that stored panel content in a detached fragment, or hid it with display: none, removed it from find-in-page entirely — so a user searching the page for a term that was demonstrably on the page got nothing. This is the same searchable-hidden-content model that hidden="until-found" exposes for non-disclosure cases; the disclosure element gets it by being what it is.

Because the three pieces landed at different times, the support posture has to be stated per piece rather than as one claim about "native accordions". The elements are long-interoperable and need no gate. The name attribute is Baseline Newly available and degrades to independent panels. ::details-content is the newest and degrades to an instant open. Its height animation also needs interpolate-size, which only Chromium-based browsers such as Chrome and Edge support, so Firefox and Safari open instantly too. On find-in-page, Chrome and Edge (97 and later) and Firefox (148 and later) expand the panel and scroll to the match, while Safari (26.2 and later) expands it but does not correctly scroll to the matching text (as of November 2026, MDN browser-compat-data). All of those statements carry an as-of date and should be re-verified against MDN or Baseline at the moment you commit, because the entire point of a dated claim is that it expires.

And the honest column. Some accordions should stay components. If open state is application state — persisted across navigation, restored from a server, or shared with something else on the page — you are managing state, and the open attribute is a rendering of that state rather than the home for it. If panels must choreograph with each other beyond one-closes-the-others, that logic does not fit in an attribute. If the design requires an animated collapse on browsers that lack ::details-content or interpolate-size — as of November 2026 that includes Firefox and Safari, which do support ::details-content — you are back to measuring heights. Our team still reaches for a component in those cases; the difference is that it is now a deliberate exception for a named reason, not the default shape of every disclosure on the page.

Project Inquiry