Back to HTML

The details and summary Elements

Coding Tutorials Team 18 June 2026

Expanding and collapsing sections is one of the most commonly built interface patterns, and it usually arrives with a pile of JavaScript, aria attributes and keyboard handling. Two native elements provide the whole thing.

The basic use

<details> <summary>What is the difference between an id and a class?</summary> <p>An id identifies one element and must be unique. A class labels any number of elements.</p> </details>

The summary is the always visible control, and everything else inside the details element is the collapsible content. The summary must be the first child, and there may only be one.

What you get without writing anything further is a focusable control, keyboard activation with both enter and space, correct announcement as a disclosure widget with its expanded state, and a working toggle.

The open attribute

A boolean attribute that makes the panel expanded initially. The browser adds and removes it as the user toggles, so it always reflects the current state and can be read from JavaScript or targeted in CSS.

details[open] summary { border-bottom: 1px solid #ddd; }

Styling the marker

The default triangle can be replaced. The marker pseudo-element is the standard way, and a widely supported alternative targets the browser specific disclosure pseudo-element.

summary { list-style: none; cursor: pointer; } summary::marker { content: ""; }

With the default removed you can add your own indicator with generated content, rotating it based on the open attribute. Keep some visible indicator, since a summary that looks like ordinary text gives no clue that it can be expanded.

The find in page behaviour

This is the detail worth knowing. Content inside a collapsed details element is present in the document rather than removed, and browsers will automatically expand a panel when a user searches the page and finds a match inside it.

That is a genuine advantage over a scripted accordion that removes content from the page, where a search finds nothing. It also means content inside collapsed panels is available to search engines, so an FAQ built this way is indexed normally.

Animating it

Historically the element could not be animated, because it switches between no height and full height with nothing in between. Newer CSS features make it possible, and support is still uneven enough that a transition should be treated as an enhancement rather than something to depend on.

Whatever approach you take, respect the reduced motion preference. An expanding panel is a small movement and it still counts.

Grouping into an accordion

Several details elements stacked together form an accordion where any number can be open at once. To make them exclusive, so opening one closes the others, the name attribute groups them in the same way it groups radio buttons.

<details name="faq"> ... </details> <details name="faq"> ... </details>

This is a recent addition and support is not universal, so treat exclusive behaviour as an enhancement. Where it is unsupported, the panels simply behave independently, which is a reasonable fallback.

The toggle event

The element fires an event whenever it opens or closes, which is the hook for anything that needs to react, such as loading content on first expansion or recording which panels a user opened.

Lazy loading content this way is genuinely useful on a page with many panels, since the markup inside a collapsed details element is still downloaded and parsed even though it is not displayed. Deferring heavy content until the panel is opened keeps the initial page light.

Where it is not the right element

Details is a disclosure widget, meaning content that is hidden and can be revealed. It is not a tab interface, where several panels share one region and exactly one is visible. Tabs have different keyboard expectations and need their own roles and handling.

It is also not a menu, a dropdown or a modal. Using it for a navigation dropdown is tempting because the toggle behaviour is free, and it announces itself as a disclosure rather than as a menu, which may or may not matter for your case.

What summary may contain

A summary accepts headings and inline content, so a heading inside one is valid and gives the panel a place in the document outline. What it should not contain is another interactive control, since a button or link inside the summary competes with the toggle for the click.

What it replaces

An accordion built by hand needs a button, an aria-expanded attribute kept in sync, an aria-controls attribute, a panel that is genuinely hidden when closed, and key handling. Every one of those is a place to introduce a bug, and the commonest is a panel hidden visually but still focusable, so keyboard focus disappears into an invisible region.

The native elements have none of those failure modes. Where the design allows it, they are simply a better answer.