The native HTML disclosure widget for expandable content. Creates an interactive widget that users can open and close without JavaScript.
Description
The <details> element creates a disclosure widget where the contents are visible only when toggled "open." It must contain a <summary> element as its first child, which provides the clickable label.
This is one of the few truly interactive HTML elements that works entirely without JavaScript. In Vanilla Breeze it serves as the foundation for several higher-level components: <accordion-wc>, <tab-set>, and tree navigation all build on native details/summary.
When to Use
- FAQ sections: Questions with expandable answers
- Collapsible content: Hide supplementary information by default
- Accordion patterns: Group related collapsible items
- Progressive disclosure: Reveal complex forms or options step by step
- Tree navigation: Collapsible menu sections (via
nav.tree)
- Code examples: Optionally viewable source code
When Not to Use
- For modals or overlays — use
<dialog>
- For dropdown menus with positioning — use
<drop-down> or <context-menu>
- When content must always be visible — avoid hiding critical-path information
- When you need keyboard arrow navigation between panels — use
<accordion-wc>
Basic Usage
A single details element with a summary label. Use the open attribute to start expanded.
1234
<details> <summary>Click to expand</summary> <p>This content is revealed when the details element is opened.</p></details>
1234
<details open> <summary>Already expanded</summary> <p>This details element starts in the open state.</p></details>
Stacked Details (Accordion)
Adjacent <details> elements automatically stack with connected borders — the border-radius is removed between siblings and the top border overlaps to prevent doubling.
Joining only happens in normal flow. When the parent is a gap-based layout primitive (<layout-stack>, <layout-grid>, any [data-layout] or [data-layout-gap] element) the items are visually separated, so each keeps its own border and radius. Use data-layout-gap="none" to join them inside a layout primitive.
123456789101112
<details> <summary>First item</summary> <p>Content for the first panel.</p></details><details> <summary>Second item</summary> <p>Content for the second panel.</p></details><details> <summary>Third item</summary> <p>Content for the third panel.</p></details>
For enhanced keyboard navigation (Arrow Up/Down, Home/End) and ARIA attributes, wrap in <accordion-wc>.
Exclusive Accordion (name attribute)
The name attribute groups details elements so only one can be open at a time. This is a native browser feature requiring no JavaScript.
12345678
<details name="faq-exclusive" open> <summary>First Question</summary> <p>Only one panel can be open at a time...</p></details><details name="faq-exclusive"> <summary>Second Question</summary> <p>Opening this will automatically close the first panel.</p></details>
Tip: The <accordion-wc> component also supports exclusive mode via single, adding keyboard navigation and View Transitions on top.
Rich Content
Details can contain any flow content: lists, definition lists, tables, images, and VB layout primitives.
As a Foundation for Web Components
In Vanilla Breeze, <details> / <summary> is the progressive enhancement base for two major web components. Both use the same HTML structure but add keyboard navigation, ARIA roles, and optional View Transitions.
accordion-wc
Wraps details elements with ARIA accordion keyboard navigation (Arrow Up/Down, Home/End) and optional single for exclusive mode.
12345678910
<accordion-wc> <details open> <summary>Section One</summary> <p>Content for the first section.</p> </details> <details> <summary>Section Two</summary> <p>Content for the second section.</p> </details></accordion-wc>
tab-set
Transforms details elements into a tabbed interface. Summaries become the tab row and content panels display below. Uses CSS display: contents on details for grid participation.
12345678910
<tab-set> <details open> <summary>Tab One</summary> <p>Panel content for the first tab.</p> </details> <details> <summary>Tab Two</summary> <p>Panel content for the second tab.</p> </details></tab-set>
Tree Navigation
The nav.tree variant uses nested details/summary for collapsible hierarchical menus. The nav context resets details styling and uses a +/− indicator instead of the chevron.
12345678910111213141516171819
<nav class="tree" aria-label="File browser"> <details open> <summary>Documentation</summary> <details> <summary>Elements</summary> <ul> <li><a href="#">Buttons</a></li> <li><a href="#">Forms</a></li> </ul> </details> <details> <summary>Layout</summary> <ul> <li><a href="#">Grid</a></li> <li><a href="#">Stack</a></li> </ul> </details> </details></nav>
See nav for more tree navigation variants.
CSS Reference
Base Styling
1234567891011121314151617181920212223242526272829
details { border: var(--border-width-thin) solid var(--color-border); border-radius: var(--radius-m);} details + details:where(:not(:is(layout-stack, layout-grid, [data-layout], [data-layout-gap]):not([data-layout-gap="none"]) > *)) { margin-block-start: calc(var(--border-width-thin) * -1); border-start-start-radius: 0; border-start-end-radius: 0;} summary::after { border-right: var(--border-width-medium) solid currentColor; border-bottom: var(--border-width-medium) solid currentColor; transform: rotate(-45deg); }summary:dir(rtl)::after { transform: rotate(135deg); } details[open] > summary::after { transform: rotate(45deg); } details > :not(summary) { padding-inline: var(--size-m); padding-block-end: var(--size-m);}
Open/Close Animation
Vanilla Breeze uses the ::details-content pseudo-element for smooth height animation. Animating block-size to auto also needs interpolate-size: allow-keywords (set on :root by VB's motion tokens), which is currently Chromium-only. This is progressive — other browsers simply show/hide instantly.
123456789101112
::details-content { block-size: 0; overflow-y: clip; transition: block-size var(--duration-normal) var(--ease-default), content-visibility var(--duration-normal) allow-discrete;} details[open]::details-content { block-size: auto;}
Context Overrides
Several contexts reset or extend the base details styling:
| Context |
What Changes |
nav |
Removes border, border-radius, and content padding. Details used for grouping, not disclosure. |
nav.tree |
Replaces chevron with +/− indicator. Adds indentation for nested levels. |
accordion-wc |
Removes the details border and radius (the accordion draws its own), restyles summary and indicator. Adds ARIA and keyboard navigation. |
tab-set |
Sets display: contents. Summary becomes tab button in grid row 1. |
@media print |
Reveals closed panels via ::details-content. Hides chevron markers. |
Print Behavior
In print stylesheets, all <details> content is forced visible regardless of the open attribute, so collapsed content is not lost when printing. The chevron indicator is hidden. Closed content lives inside the ::details-content pseudo-element (hidden with content-visibility), so the print rule targets that box rather than the children.
12345678
@media print { details::details-content { content-visibility: visible; block-size: auto; } summary::after { display: none; }}
Attributes
| Attribute |
Type |
Description |
open |
boolean |
When present, the content is visible. Toggled by user interaction or JavaScript. |
name |
string |
Groups details elements. Only one with the same name can be open at a time. |
JavaScript API
The <details> element can be controlled programmatically via the open property and the toggle event.
123456789101112
const details = document.querySelector('details'); console.log(details.open); details.open = !details.open; details.addEventListener('toggle', (event) => { console.log('Now', event.target.open ? 'open' : 'closed');});
Events
| Event |
Description |
toggle |
Fired when the open state changes. The open property reflects the new state. |
Accessibility
Built-in Accessibility
- The
<summary> element receives automatic button-like keyboard behavior
- Screen readers announce the expanded/collapsed state
- Enter and Space keys toggle the state when summary is focused
Best Practices
- Always include a
<summary> as the first child
- Keep summary text concise and descriptive
- Avoid nesting interactive elements inside
<summary>
- Ensure hidden content is not critical path information
- For multiple related panels, consider
<accordion-wc> for keyboard arrow navigation between summaries
Keyboard Support
| Key |
Action |
| Enter |
Toggle open/closed when summary is focused |
| Space |
Toggle open/closed when summary is focused |
Related
<summary> — Required clickable child that provides the toggle label
<accordion-wc> — Enhanced accordion with Arrow/Home/End keyboard navigation and ARIA
<tab-set> — Tab interface built on details/summary with grid layout
<nav> — Tree navigation variant uses details for collapsible sections
<dialog> — For modal overlays rather than inline disclosure
open — The expanded state, and exclusive accordions with name
hidden — hidden="until-found" for collapsed content that find-in-page can reveal
Browser Support
The <details> element is supported in all modern browsers. The name attribute for exclusive accordions is supported in Chrome 120+, Safari 17.2+, and Firefox 130+. The ::details-content pseudo-element is supported in Chrome 131+, Safari 18.4+ and Firefox 143+; the open/close height animation additionally needs interpolate-size, which only Chromium supports, so Safari and Firefox open and close instantly. Printing closed panels relies on ::details-content; older browsers print only open panels.