details

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.

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.

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.

Tip: The <accordion-wc> component also supports exclusive mode via data-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 data-single for exclusive mode.

tab-set

Transforms details elements into a tabbed interface. Summaries become tab buttons in row 1, content panels display in row 2. Uses CSS display: contents on details for grid participation.

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.

See nav for more tree navigation variants.

CSS Reference

Base Styling

Open/Close Animation

Vanilla Breeze uses the ::details-content pseudo-element for smooth height animation. This is progressive — browsers that don't support it simply show/hide instantly.

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 Sets display: contents on details. Adds ARIA and keyboard navigation.
tab-set Sets display: contents. Summary becomes tab button in grid row 1.
@media print Forces all details open. 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.

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.

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

Patterns Using This Element

The <details> element is used across many patterns:

FAQ

Accordion-style questions and answers

Sidebar

Collapsible navigation sections

Wizard

Multi-step form disclosure

Checkout

Expandable checkout sections

App Shells

Collapsible application panels

Timeline

Expandable event details

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 animation pseudo-element works in Chrome 131+ and Safari 17.5+; other browsers fall back to instant show/hide.