<summary>
The always-visible heading of a `<details>` element, which expands and collapses the content.
- Display
- list-item
- Closing tag
- Required
- Permitted content
- Phrasing content, optionally with
<h1>-<h6>headings
Example
#<style>
summary { cursor: pointer; font-weight: 600; }
summary::marker { color: #f97316; }
</style>
<details>
<summary>Module 3: forms (6 lessons)</summary>
<ol>
<li>The form element</li>
<li>Text fields</li>
<li>Checkboxes and radio buttons</li>
</ol>
</details>Definition and usage
#The <summary> element is the label of a <details> widget: the text that is always visible and that you click to expand or collapse the rest. It must be the first child of <details>. If you leave it out, the browser shows its own label, usually “Details”.
The browser treats <summary> like a button: you can reach it with the Tab key and activate it with Enter or Space. It has display: list-item by default, which is why it shows a triangular marker that changes direction when the section is expanded.
Inside it you can put text, emphasis, and even a heading (<h1>-<h6>) if the section is part of the document structure. Avoid links and buttons in it, because clicking them would also toggle the section.
Syntax
#<summary>Heading text</summary>Attributes
#This element has no attributes of its own. It supports the global attributes, such as class, id and hidden.
Default CSS
#Most browsers display this element with these default styles:
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
#- The triangle is a list marker. You can hide it with
summary { list-style: none; }, and in older versions of Safari also withsummary::-webkit-details-marker { display: none; }. - Write text that says what will expand, for example “Show the solution”, rather than just “More”.
Related entries
#- <details>A collapsible section: the `<summary>` heading is always visible, and the rest of the content appears on click.
- <button>A clickable button: submits a form, clears it, or runs an action on the page.
- <h1>-<h6>Headings at six levels, from the most important h1 to the least important h6. Together they form the page’s outline.
Practise it in lessons
#Spotted a mistake or missing an example? Write to us.