CHAPTER 41 · HTML
Details and summary: let readers open extra information
Build expandable hints with ordinary HTML. Understand the visible summary, the open state and a group that can show one answer at a time.
Download example files (ZIP)Start with a familiar folded note
Read the syntax in order
<details>
<summary>What should I save?</summary>
<p>Save the page with an .html extension.</p>
</details>Closed by default; open when requested
Use a keyboard as well as a mouse
A named group can open one answer at a time
Know when to leave the answer visible
Follow the idea
- 1Read a specific summary
- 2Try the question first
- 3Open or close the details
- 4Keep essential instructions visible
The answer stays in the document; a closed panel is not private.
Complete program: study-details.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Expand a Study Hint</title>
</head>
<body>
<h1>Read a hint when you need it</h1>
<main>
<p>Try explaining a relative link before opening the hint.</p>
<details>
<summary>How can I find a file in the same folder?</summary>
<p>Use its filename, such as notes.html, as the relative link address.</p>
</details>
<details open>
<summary>What should I check after saving?</summary>
<p>Refresh the browser and confirm that your latest change appears.</p>
</details>
</main>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Complete program: grouped-details.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>One Question at a Time</title>
</head>
<body>
<h1>Review two file questions</h1>
<main>
<p>These answers share a group. In supporting browsers, opening one closes the other.</p>
<details name="file-review" open>
<summary>Why did my change not appear?</summary>
<p>Check that you saved the file you opened, then refresh the browser.</p>
</details>
<details name="file-review">
<summary>Why does my link reach the wrong file?</summary>
<p>Read the path from the folder containing the current page.</p>
</details>
</main>
</body>
</html>This preview shows the example in a browser. Save the complete code in local files to test links between pages and downloads. Same-page section links work here.
Problem and solution
Common mistakes and useful tips
Put one summary first inside details. Do not use open="false" to mean closed. Do not hide essential instructions. Do not remove keyboard focus styling. Do not treat collapsed content as secret. Test named groups instead of assuming identical browser support.
Practice questions
Which element provides the visible label? Which answer begins open in the first program? How do you make a details element start closed? What does the shared name do? Does a closed answer disappear from the source? Save the first program and toggle both labels with the keyboard. What remains visible?
Check your practice answers
Summary. The second, because its details element has open. Omit open rather than setting it to false. It groups the disclosures so supporting browsers allow one open member at a time. No. It is still document content. Each summary remains visible; only its extra content changes visibility. No JavaScript is needed for this basic action.
Interview questions
Do details and summary require JavaScript?
How is open different from an ordinary text setting?
Why choose a specific summary label?
When is details unsuitable?
Quick revision
Summary names the expandable area. Open sets the starting state. Shared names can group answers. Test mouse and keyboard operation.