- Home
- /
- Tutorials
- /
- HTML Tutorial
- /
- HTML <details> Tag
HTML Tags
HTML <details> Tag
The details tag makes a box that opens and closes when you click its title, with no JavaScript. It is perfect for FAQs, "show more" sections and optional help text.
The always-visible title is a summary tag as the first child. Everything after it is hidden until the reader opens the box.
Syntax
html
<details>
<summary>Title or heading</summary>
<!-- Hidden content that can be expanded -->
</details>| Attribute | What it does |
|---|---|
| open | The box starts expanded. It is added and removed automatically as the reader clicks. |
| name | Gives several details boxes the same group name, so opening one closes the others, like an accordion. |
Global attributes such as id and class also work.
Example
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Details Tag Example</title>
</head>
<body>
<h1>Frequently Asked Questions</h1>
<details>
<summary>What is HTML?</summary>
<p>HTML (HyperText Markup Language) is the standard markup language for creating web pages.</p>
</details>
<details open>
<summary>What is CSS?</summary>
<p>CSS (Cascading Style Sheets) is used to style and layout HTML content.</p>
</details>
</body>
</html>You see two questions. The first is closed; click it to show the answer. The second starts open because it has the open attribute.
An accordion with name
Only one answer open at a time
html
<details name="faq">
<summary>What is HTML?</summary>
<p>The language that structures web pages.</p>
</details>
<details name="faq">
<summary>What is CSS?</summary>
<p>The language that styles them.</p>
</details>Opening one closes the other. This is new, but supported by every current browser.
Reacting with JavaScript
The toggle event fires whenever a box opens or closes, and element.open tells you its state. That is useful for loading content only when someone opens a box.
Browser Support
Chrome | Edge | Firefox | Safari | Opera | IE9+ |
|---|---|---|---|---|---|
| Yes | Yes | Yes | Yes | Yes | Yes |
Supported by every current browser. In Internet Explorer the content is simply always visible.
Good to know
- Search inside the page (Ctrl + F) finds text in closed details boxes in modern browsers and opens them automatically.
- Do not hide important information inside a closed box. Readers may never open it.
- Style the open state with
details[open], and the arrow with thesummarystyles shown in the summary lesson.
HTML <details> Tag exercises
Add a disclosure
Make text that opens on a click. The line to click says More info, and the paragraph it opens says Free in India.
Result
