details
A disclosure widget that can open and close.
Learn details, summary, dialog as part of the HTML element system: when to use it, how it fits inside a document and what mistakes to avoid.
Interactive
details and summary create disclosure behavior. dialog creates modal or non-modal dialog behavior. These elements give you browser-native interaction when used carefully.
Native interaction is valuable because it often brings keyboard and accessibility behavior for free, but you still need clear labels, focus handling and sensible content.
details, summary, dialog. Native disclosure and dialog behavior. Syntax in context
details is excellent for FAQs and expandable explanations. dialog is useful for modals when focus and closing behavior are handled properly.
<details> <summary>What is semantic HTML?</summary> <p>Semantic HTML uses elements for their meaning, not only their visual style.</p> </details> <dialog id="lesson-dialog"> <p>Dialog content needs focus and close behavior.</p> </dialog>
Good versus weak
<details> <summary>What is semantic HTML?</summary> <p>Semantic HTML uses elements for their meaning, not only their visual style.</p> </details> <dialog id="lesson-dialog"> <p>Dialog content needs focus and close behavior.</p> </dialog>
<div onclick="toggleAnswer()">Question</div> <div class="modal">Hidden modal with no focus handling</div>
Rules that matter
The summary text should clearly describe what opens.
Expandable content is useful, but essential information should not be buried.
When using dialog, handle open, close and focus return properly.
Native controls often beat custom div-based interaction.
Production thinking
Beginners often ask why this is not just a div with styling. The reason is that HTML is read by browsers, search engines, screen readers and future developers. Clear meaning makes the page easier to use and maintain.
Native details/summary is keyboard accessible in modern browsers. Dialog still requires thoughtful focus and close behavior.
Use interactive elements for FAQs, settings panels and modals, but test keyboard behavior before shipping.
Live code lab
Edit the HTML or CSS, then use Run to refresh the preview. The preview is isolated, so links and forms stay inside this practice area.
Mini assignment
Practice assignment
Try it yourself
Self-check
Do not only read this page. Answer these questions out loud or write the answers in your own notes. If one answer feels vague, revisit the examples before moving on.