Skip to main content

HTML Tags

HTML <summary> Tag

Written by Updated HTML <summary> Tag exercises

The summary tag is the always-visible, clickable line of a details box. Click it and the hidden content opens; click again and it closes. No JavaScript needed.

<summary> only works as the first child of a details element. The browser makes it focusable and clickable, adds the little arrow, and handles the opening and closing.

Syntax

html

<details>
  <summary>Click to expand</summary>
  <!-- Hidden content that appears when summary is clicked -->
</details>

It has no attributes of its own; the global ones such as class and id work. To make a details box start open, put the open attribute on <details>, not on <summary>.

Example

html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Summary Tag Example</title>
</head>
<body>
  <h1>Interactive FAQ</h1>

  <details>
    <summary>What is JavaScript?</summary>
    <p>JavaScript is a programming language used to make web pages interactive.</p>
  </details>

  <details>
    <summary>What is HTML?</summary>
    <p>HTML (HyperText Markup Language) is used to structure content on the web.</p>
  </details>
</body>
</html>

Each question is a clickable line with an arrow. Click one to show its answer. Keyboard users can Tab to a question and press Enter or Space.

Styling the arrow

The arrow is a list marker, so you change it with CSS:

Replace the default arrow

css

summary {
  cursor: pointer;
  list-style: none;            /* hides the arrow in most browsers */
}
summary::-webkit-details-marker {
  display: none;               /* hides it in older Safari */
}
summary::before {
  content: "+ ";
}
details[open] summary::before {
  content: "− ";
}

Browser Support

Chrome
Edge
Firefox
Safari
Opera
IE9+
YesYesYesYesYesYes

Supported in all current browsers. Internet Explorer never supported it; there the content is simply always visible.

Good to know

  • Keep the summary text short and clear, like a question or a section title. It is what screen readers announce as the button.
  • Do not put links or buttons inside <summary>. Clicking them also toggles the box, which feels broken.
  • If you leave out <summary>, the browser shows the word "Details" instead.

HTML <summary> Tag exercises

Label a disclosure

Make text that opens on a click, with the label Read more and the paragraph The rest of the story.

Result

Check your answer to see it here.