<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
Example
#<details>
<summary>Exercise hint</summary>
<p>Remember that the <code><img></code> element has no closing tag.</p>
</details>
<details>
<summary>Show the solution</summary>
<pre><code><img src="cat.jpg" alt="A ginger cat sleeping on a windowsill"></code></pre>
</details>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
#<details>
<summary>Heading</summary>
Hidden content…
</details>Attributes
#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.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 attributeThe section is expanded. Set it in your code to make the content visible right away, for example in the first FAQ question.
<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>name
textGroups several <details> elements so that only one can be open at a time. It has worked in all major browsers since 2024.
<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>Default CSS
#Most browsers display this element with these default styles:
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
openproperty, and react to changes in thetoggleevent. - The browser handles the keyboard itself and tells screen readers about the section’s state. Don’t add your own roles or an
aria-expandedattribute to<summary>.
Related entries
#- <summary>The always-visible heading of a `<details>` element, which expands and collapses the content.
- <dialog>A dialog or modal window: a confirmation, form, or message shown above the rest of the page.
- <section>A thematic part of a document, usually with its own heading.
- <button>A clickable button: submits a form, clears it, or runs an action on the page.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.