HTML details element

Reference for the HTML details element: native disclosure, the open attribute, and where summary belongs.

标签页正文目前为英文。

The details element is a disclosure widget: a summary and additional content that the user can show or hide with built-in user-agent behavior. This page covers summary here rather than as a thin page. details and summary are not in the original tag catalog cards; this page is the dedicated reference.

Both start and end tags are required. The first summary element child, if any, provides the disclosure label. Other content is the remainder of the widget. If there is no summary, the user agent supplies its own label. Script is not required to open or close a details element.

Examples were checked with Python 3.13's html.parser as a structural tree, and with the site build. Native open and close, keyboard access, and assistive-technology mappings were not tested in a browser.

Official sources: MDN <details> element and the WHATWG HTML Living Standard. Fragments were checked with Python 3.13 html.parser. That parser builds an element tree; it is not a WHATWG conformance checker, and this is not a browser or accessibility test.

HTML tag catalog → · HTML tutorial overview →

Purpose, summary position, and the open attribute

Put a summary element first whenever you provide one. The HTML Standard treats the first summary element child as the summary, even if earlier siblings exist, but placing it first keeps the structure and the visible control aligned. summary's content is phrasing content and should describe what is disclosed.

The open attribute is a boolean. When it is present, the additional content is shown. When it is omitted, the widget is closed in the markup. The user agent can toggle that state without any script. The current HTML Standard also defines a name attribute so several details elements can form an exclusive accordion group; that attribute is newer, support varies, and exclusive opening was not demonstrated or tested here.

Native disclosure with summary first, and one open widget

<details>
  <summary>Title</summary>
  <p>Hidden until opened</p>
</details>
<details open>
  <summary>Title</summary>
</details>

summary is the first child and captions the widget. The open attribute shows the remaining content in the markup.

AttributeDescription
openA boolean on details. When present, the widget is shown as open in the markup. Toggling is a user-agent behavior and was not executed here.
nameOptional. In current HTML, details elements that share a name form an exclusive group. This is a newer feature, and it is not used in the example.
  • No script is attached. This fragment does not record a click, toggle event, or computed open state from a browser.
html
<details>
  <summary>Shipping times</summary>
  <p>Orders usually leave the warehouse in two business days.</p>
</details>
<details open>
  <summary>Returns</summary>
  <p>Unused items can be returned within 30 days.</p>
</details>

What this markup means

Each details element has a summary as its first element child, which is the disclosure label. The first widget has no open attribute, so it is closed in the markup. The second has open, so its paragraph is shown in the markup. Opening or closing the widgets is left to a user agent and was not performed here.

Related: <dialog>, HTML tag catalog, HTML tutorial overview

MDN documentation → · WHATWG HTML Standard →

Accessibility and limits

summary should have accessible text that still makes sense when the rest of the content is hidden. Do not rely on a missing summary and the user-agent fallback label if you can write a specific caption.

details is for optional disclosure, not for modal dialogs or navigation that must stay visible. Styling the disclosure marker and the exact keyboard or screen-reader experience vary by user agent and were not measured here.