HTML Reference ยท Interactive Elements
The <details> element
Reference for the HTML <details> element: building collapsible sections and exclusive accordions without JavaScript, the open and name attributes, and the toggle event.
The <details> element creates a disclosure widget: a box whose content is hidden until the user opens it. Its first child, a <summary>, is the always-visible label; clicking it (or pressing Enter or Space while it has focus) shows or hides everything else. The browser handles the state, the keyboard support and the accessibility, with no script required.
<details> <summary>Shipping costs</summary> <p>Orders over $40 ship free. Smaller orders cost $4.50.</p> </details>
Try it
Give several <details> elements the same name and they become an exclusive accordion: opening one closes whichever other member of the group was open.
Attributes
| Attribute | Values | Description |
|---|---|---|
open |
Boolean | When present, the content is shown. The browser adds and removes it as the user toggles the widget, so you can read or set it (or the open property) from script. |
name |
Any string | Groups <details> elements that share the same value into an exclusive accordion: at most one of them can be open at a time. |
It also accepts the global attributes.
Usage notes
- The
toggleevent. It fires on the<details>element after theopenstate changes, whether the user or a script caused it. Several quick changes may be combined into a single event, so readelement.openinside the handler instead of counting events. - Put
<summary>first. Only a<summary>that is the first child acts as the label. If there is none, the browser supplies a generic label such as "Details", which is rarely what you want. - Exclusive groups don't stop closing. With
name, the user can still close the open item and leave every member closed. If you setopenon more than one member in your markup, the browser keeps only the first one open. - Styling the marker. The triangle comes from the summary's
list-itemdisplay. Change it withsummary::marker, or remove it withsummary { list-style: none; }(older Safari versions also needsummary::-webkit-details-marker { display: none; }). - Hidden content is still in the page. Search engines can read it, and some browsers open a closed
<details>automatically when find-in-page or a URL fragment points at text inside it. - Know when not to use it. Use
<details>for optional, secondary content such as FAQs or advanced settings. Don't use it to hide the main content, and don't use it for menus or tabs, which need different keyboard behavior.
Technical summary
| Content categories | Flow content, interactive content, palpable content |
| Permitted content | One <summary> element followed by flow content |
| Tag omission | None; both the start and end tags are required |
| Permitted parents | Any element that accepts flow content |
| Implicit ARIA role | group |
| DOM interface | HTMLDetailsElement |
| Default display | block |
Browser support
<details> and the toggle event work in every current browser. The name attribute for exclusive accordions is newer: it has been Baseline since 2024, so very old browsers simply let several items open at once.
Related
<summary>โ the visible label of a<details>widget<dialog>โ a modal or non-modal dialog box- Lesson: Collapsible Sections with Details