Not everyone uses a mouse to explore a website. Good HTML must also make sense through a keyboard or screen reader.
What You Need to Know
Details provides simple show-and-hide behavior with a summary. A scripted accordion may be useful for special interaction rules, but you must then implement keyboard access and state announcements too.
Try the Example
Take a look at the example. We’ll explain the important lines right below it.
<details>
<summary>What is semantic HTML?</summary>
<p>It uses elements that explain what each part of a page means.</p>
</details>
Let’s Read the Code
- <details>: Details makes a section expandable without requiring a custom script.
- <summary>: Summary is the label people activate to expand or collapse details.
Read the named elements and attributes together. They explain how the browser connects this feature to the rest of the page.
What Happens in the Browser?
Try this with Tab and Shift+Tab. If you can, inspect the accessibility tree too; appearance alone does not tell the whole story.
Try a different way of reading. Read only the headings and labels, or navigate through links without looking at the rest of the page. If the page still makes sense, the underlying HTML is probably doing an important part of its job.
Your Turn
Use Tab and Shift+Tab to visit the controls, then read their labels aloud. Is the purpose of each one clear?
Common Beginner Mistakes
- Expecting the page to run scripted behavior when the required JavaScript is missing.
- Check the same result using both the browser and a keyboard, not only by looking at the screen.
Key Takeaways
- Details provides simple show-and-hide behavior with a summary.
- <details>: Details makes a section expandable without requiring a custom script.
- Test the behavior you expect rather than trusting how the snippet looks in your editor.