Ad space (banner)
🎨HTML & CSS Lessons
Lesson 32 / 50

The details and summary Tags (Building a Collapsible Panel)

In this lesson you'll learn how to build a collapsible panel using the details and summary tags, so you can achieve an accordion UI without JavaScript. This is for people searching "HTML details summary usage."

Combining <details> and <summary> lets you build a click-to-expand "accordion panel" without writing any JavaScript. This is used on things like a frequently-asked-questions (FAQ) page.

The sample code prepares two <details> blocks, each with a question in its <summary> and an answer <p> inside it. Try actually clicking on one, and confirm how the browser automatically provides an expand/collapse icon and motion.

A common beginner stumbling block is how to customize the expand/collapse appearance with your own design. To remove or change the browser's default triangle icon, you need to adjust the <summary>'s list-style or a pseudo-element — it takes a bit of extra work.

Whatever's written in <summary> always stays visible, and clicking it expands or collapses the contents of <details>. Since this is a standard browser feature, its advantage is being able to easily implement a collapsible display without any extra code.

HTML & CSS
OUTPUT

💡 The preview runs entirely on this page — nothing is sent externally.

Ad space (banner)
Ad space (in-article)