open

Toggle visibility of details disclosure widgets and dialog elements. A boolean attribute that controls whether expandable or overlay content is currently shown.

Overview

The open attribute is a boolean attribute that controls the visibility of expandable content. It applies to two elements:

  • <details> — controls whether the disclosure widget is expanded or collapsed
  • <dialog> — controls whether the dialog is visible (non-modal)

When open is present, the content is shown. When absent, it is hidden.

Details Element

On <details>, the open attribute determines whether the content below the <summary> is visible. Users can toggle it by clicking the summary. Add open in markup to have the section expanded on page load.

Exclusive Accordions with name

The name attribute on <details> creates an exclusive accordion group. When multiple <details> elements share the same name, opening one automatically closes the others — no JavaScript required.

Dialog Element

On <dialog>, the open attribute makes the dialog visible as a non-modal overlay. However, for modal dialogs you should use showModal() instead, which adds the open attribute automatically and also provides backdrop, focus trapping, and Escape-to-close behavior.

ApproachBackdropFocus TrapEscape to CloseTop Layer
open attributeNoNoNoNo
showModal()YesYesYesYes
show()NoNoNoNo

Styling Open State

Use the [open] attribute selector to style expanded details or visible dialogs.

JavaScript Events

The toggle event fires on <details> when its open state changes, whether by user interaction or script. The open property reflects the current state.

Accessibility

  • Screen readers announce <details> as a disclosure widget with its expanded/collapsed state.
  • The <summary> element is focusable and activatable via keyboard (Enter and Space).
  • For <dialog>, always prefer showModal() over the open attribute — it ensures proper focus management and keyboard behavior.

Limitations

  • The name attribute for exclusive accordion groups is relatively new. Older browsers will treat each <details> independently.
  • There is no built-in animation for <details> open/close transitions. CSS transitions on height require workarounds.
  • Setting open directly on a <dialog> in markup creates a non-modal dialog with no backdrop or focus trapping, which is rarely what you want.
  • The toggle event is not cancellable — you cannot prevent the state change from within the handler.

See Also

  • <details> — the disclosure widget element
  • <dialog> — the dialog element
  • hidden — hide elements entirely from rendering
  • popover — overlay content with light-dismiss behavior