<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
On this page

Example

#
HTML
<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>
Preview

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

#
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:

CSS
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 with summary::-webkit-details-marker { display: none; }.
  • Write text that says what will expand, for example “Show the solution”, rather than just “More”.

Related entries

#

Practise it in lessons

#

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