June 15, 2025
O. Wolfson
The <details> and <summary> elements are simple yet powerful HTML5 features that allow you to create collapsible content sections without relying on JavaScript. These elements improve accessibility and provide a clean user experience out of the box.
<details> and <summary>?<details> is a container for content that can be expanded or collapsed by the user.<summary> defines a visible label or heading for the collapsible section. Clicking this toggles the visibility of the content inside <details>.This functionality works natively in all modern browsers and can be styled with CSS.
HTML stands for HyperText Markup Language. It is the standard language for creating web pages.
html<details>
<summary>What is HTML?</summary>
<p>
HTML stands for HyperText Markup Language. It is the standard language for
creating web pages.
</p>
</details>
When the user clicks “What is HTML?”, the paragraph becomes visible. Clicking again hides it.
Although <details> has a default arrow indicator and styling, you can override these with CSS:
cssdetails summary {
font-weight: bold;
cursor: pointer;
}
details[open] summary {
color: teal;
}
You can also hide the default marker and use your own:
csssummary::-webkit-details-marker {
display: none;
}
Then use a background image or icon to indicate the open/closed state.
These elements are accessible by default:
Tab and Enter.Still, make sure the content inside is structured properly with headings and semantic HTML for clarity.
<details> and <summary> offer a semantic and accessible way to create collapsible content without any JavaScript. They're perfect for simple interactions like FAQs or expandable instructions, and they enhance both usability and performance in modern web apps.