How do I use details and summary for optional page information?
Quick answer
Use <summary> as a short label that tells readers what optional information is inside; put the information itself in the rest of its parent <details> element. The summary must be the first child of <details>, and activating it toggles the disclosure open or closed. Write the label so its purpose is understandable on its own. Browser and assistive-technology behavior can vary in some cases. [S1]
The question, the details, the next step.
A practical checklist
Put
<summary>as the first child of its parent<details>.Use a short summary that names the optional information’s subject.
Place the explanation or list in the rest of
<details>.Read the summary alone and check that its purpose is clear.
Confirm the revealed content matches what the summary promises.
A few more useful answers
Can the summary contain the full explanation?
Its main job is to label the disclosure. Keep detailed material in the remainder of <details> so the summary stays a useful, concise description. [S1]
Does the summary have to be the first thing inside details?
Yes. <summary> must be the first child of its parent <details> element. [S1]
Will every browser or assistive technology behave exactly the same way?
The source notes that behavior can vary in some cases. The basic element guidance does not establish identical behavior across browsers and assistive technologies. [S1]
Sources
References used for this guide.
- [S1] MDN: The HTML summary disclosure element developer.mozilla.org · Checked
