<details>

A collapsible section: the `<summary>` heading is always visible, and the rest of the content appears on click.

Display
block
Closing tag
Required
Permitted content
One <summary> element, followed by flow content
On this page

Example

#
HTML
<details>
  <summary>Exercise hint</summary>
  <p>Remember that the <code>&lt;img&gt;</code> element has no closing tag.</p>
</details>
<details>
  <summary>Show the solution</summary>
  <pre><code>&lt;img src="cat.jpg" alt="A ginger cat sleeping on a windowsill"&gt;</code></pre>
</details>
Preview

Definition and usage

#

The <details> element creates an expand/collapse widget without a single line of JavaScript. Only its first <summary> element is always visible, and the rest of the content appears when you click it or press Enter or Space. It’s a good fit for FAQs, exercise hints, solutions to check, and technical details.

The open attribute decides whether the section is expanded. The browser adds and removes it on every click, and you can set it in your code to make the section open from the start. Every state change fires a toggle event.

Several <details> elements with the same name attribute form an accordion: opening one section automatically closes the others. Screen readers announce <summary> as a button and report whether the section is expanded or collapsed.

Syntax

#
Syntax
<details>
  <summary>Heading</summary>
  Hidden content…
</details>

Attributes

#
  • open

    boolean attribute

    The section is expanded. Set it in your code to make the content visible right away, for example in the first FAQ question.
  • name

    text

    Groups several <details> elements so that only one can be open at a time. It has worked in all major browsers since 2024.

The element also supports all global attributes, such as class, id, style and hidden.

Attributes in practice

#

open

boolean attribute

The section is expanded. Set it in your code to make the content visible right away, for example in the first FAQ question.

HTML
<details open>
  <summary>How much time a day should I study?</summary>
  <p>Consistency matters more than session length. Half an hour a day is enough to start.</p>
</details>
Preview

name

text

Groups several <details> elements so that only one can be open at a time. It has worked in all major browsers since 2024.

HTML
<details name="faq" open>
  <summary>Where should I start learning?</summary>
  <p>With HTML and CSS, because you see the results right away in the browser.</p>
</details>
<details name="faq">
  <summary>Do I need to know English?</summary>
  <p>It helps, but it isn’t necessary at the start.</p>
</details>
<details name="faq">
  <summary>What computer should I learn on?</summary>
  <p>Any computer with a modern browser will do.</p>
</details>
Preview

Default CSS

#

Most browsers display this element with these default styles:

CSS
details {
  display: block;
}
details > summary:first-of-type {
  display: list-item;
  list-style: disclosure-closed inside;
}
details[open] > summary:first-of-type {
  list-style-type: disclosure-open;
}

Browser support

#

Widely available · since 2020

Works in all modern browsers, phones included. You can use it without worry.

  • Chrome
  • Edge
  • Firefox
  • Safari

Good practices

#
  • Don’t hide content in <details> that everyone needs to read. Collapsed sections are easy to miss.
  • You can read and change the section’s state in JavaScript through the open property, and react to changes in the toggle event.
  • The browser handles the keyboard itself and tells screen readers about the section’s state. Don’t add your own roles or an aria-expanded attribute to <summary>.

Related entries

#

Practise it in lessons

#

Spotted a mistake or missing an example? Write to us.