Details and Summary
What Is It?
Details creates a section that a reader can open and close without JavaScript.
What the Tags Mean
details: wraps the hidden content.summary: the visible heading people click.open: shows the content from the start.
Example 1
Save each example as index.html and open it in your browser. Each code block is a complete page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Details and Summary</title>
</head>
<body>
<details>
<summary>What should I bring?</summary>
<p>Bring a notebook and a pencil.</p>
</details>
</body>
</html>Browser preview
What you see: Click the question to show the answer. Click again to hide it.
Example 2: Another Use
Use open when you want the answer to start visible.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Details and Summary</title>
</head>
<body>
<details open>
<summary>Class time</summary>
<p>Saturday at 10 am.</p>
</details>
</body>
</html>Browser preview
Simple Tip
Put summary first inside details. Keep essential instructions visible outside a closed section.
Try It Yourself
Write a second question and answer.