Web development

Create a disclosure with details and summary

Use details and summary for a simple expandable section without writing custom toggle JavaScript. Put the control’s visible label in summary and the hidden-by-default content after it.

Worked example

HTML example · save as example.html and open in a browser

<details>
  <summary>Which files should I select?</summary>
  <p>Select the extracted JSON files, not the ZIP archive.</p>
</details>

How it works

The browser supplies expansion state and keyboard interaction. Adding the open attribute makes the section expanded initially. This is a useful fit for optional supporting instructions that should remain available even when JavaScript fails.

Limits and mistakes

Do not hide essential steps merely to make the page shorter. Complex interactive controls inside summary can create confusing activation behavior. Style the disclosure while preserving a visible indicator and an obvious focus state.

Check the result

Tab to the summary and expand it using the keyboard. Confirm the explanation becomes visible and the control still works with JavaScript disabled.

Sources

Reference documentation for the behavior used in this guide: