<details> & <summary> Tags in HTML

Quick facts

CategoryFlow content, interactive content, palpable content
Content modelOne <summary> first, followed by flow content
Tag omissionNeither the start nor the end tag can be omitted, for either element
Permitted parents<details>: any element that accepts flow content. <summary>: a <details>, as its first child
DOM interfacesHTMLDetailsElement, HTMLElement (<summary>)

Syntax

<details> <summary>What is HTML?</summary> <p>HTML is the language used to structure web pages.</p> </details>

Live example

Edit the code below and watch the preview update instantly.

index.html
Preview

Attributes

<details>

AttributeDescription
openShows the content when the page loads; it is added and removed as the reader opens and closes it
nameDetails elements that share a name form an accordion: opening one closes the others

<summary>

AttributeDescription
—Only the global attributes apply.

Common examples

An FAQ list

Each question is a summary; the answer stays hidden until clicked. Search engines can still read it.

<details> <summary>Do you ship internationally?</summary> <p>Yes, we ship to over 50 countries.</p> </details> <details> <summary>How long does delivery take?</summary> <p>3–5 working days.</p> </details>

Open by default

Add the open attribute to show the content when the page loads.

<details open> <summary>Installation steps</summary> <ol> <li>Download the file.</li> <li>Unzip it.</li> </ol> </details>

Styling the marker and open state

Replace the arrow with your own icon and change the look while it’s open.

<style> summary { cursor: pointer; list-style: none; } summary::-webkit-details-marker { display: none; } summary::after { content: " +"; } details[open] summary::after { content: " −"; } </style>

<details> vs a JavaScript accordion

Before <details>, accordions needed JavaScript to show and hide each panel, plus extra ARIA attributes so screen readers knew whether they were open. <details> does all of that by itself: it works with the mouse and keyboard, announces its state, and even works with JavaScript switched off.

A custom JavaScript accordion still makes sense for complex animations or designs the built-in element can’t manage. For FAQs, “read more” sections and simple toggles, <details> is less code and fewer bugs. Add the name attribute to make a group where only one panel opens at a time.

<details>JS accordion
JavaScript neededNoYes
Keyboard & screen reader supportBuilt inYou build it
AnimationsLimitedFull control

Common mistakes to avoid

  • Leaving out <summary>. The browser then shows a generic “Details” label.
  • Putting buttons or links inside the summary. Clicking them also toggles the panel and confuses keyboard users; keep the summary as plain text.
  • Hiding essential information. Prices, warnings and the main answer to the page’s question should be visible without clicking.
  • Removing the marker without another hint. Without an arrow or +/− sign, visitors may not realise the line is clickable.

Accessibility & SEO tips

  • Collapsed content is still in the HTML, so search engines can read and index it — a good way to keep long FAQ pages tidy.
  • Pair visible FAQs built with details and summary with FAQPage structured data so search engines understand the questions and answers.
  • Browser search (Ctrl+F) can find text inside closed details in modern browsers and opens the panel automatically.

Browser support

Supported in all modern browsers, including Chrome, Edge, Firefox, Safari and their mobile versions. It was introduced with HTML5, and only very old browsers such as Internet Explorer 8 needed workarounds. The name attribute for one-open-at-a-time groups works in all current browsers.

Related tags

Frequently asked questions

How do I make only one <details> open at a time?
Give each <details> the same name attribute, for example name="faq". Opening one then closes the others automatically, creating an accordion with no JavaScript. Older browsers simply let several stay open.
How do I change or remove the arrow on <summary>?
Style it with CSS. summary { list-style: none; } removes the marker in most browsers (add summary::-webkit-details-marker { display: none; } for older Safari), and you can add your own icon with summary::after.
Is text inside a closed <details> indexed by Google?
Yes. The text is part of the page's HTML, so search engines can read and index it even while the section is closed. It's a good, SEO-friendly way to keep long pages tidy.
Can I animate opening and closing a <details> element?
Partly. Modern browsers support animating the content with the ::details-content pseudo-element and interpolate-size; elsewhere it simply opens instantly, which is fine.
How do I open or close a <details> element with JavaScript?
Set its open property: element.open = true opens it and element.open = false closes it. Listen for the toggle event to react when it changes.
Is <details> accessible?
Yes. The summary works as a button with the keyboard (Enter or Space), and screen readers announce whether it is expanded or collapsed.