Live Preview
Click the summary to toggle the hidden paragraph:
What is HTML?
HTML structures content on the web using elements like headings, paragraphs, and links.

By the end of this tutorial, you’ll build native collapsible sections with <details> and <summary>—no JavaScript required.
Wrap hidden content in <details> with <summary> as the label.
Provide the clickable heading users see before expanding.
Start expanded on page load when content should be visible.
Group panels for exclusive accordion behavior.
Stack multiple disclosure widgets for Q&A sections.
Customize disclosure appearance with modern CSS.
<details> Tag?The details element (<details>) is a disclosure widget. It holds content that can be hidden or shown. The first <summary> child provides the clickable label; everything else inside is the revealed content.
Browsers provide native expand and collapse behavior. Click or tap the summary to toggle the hidden content—keyboard support is built in.
Common uses include FAQ answers, optional product specs, tutorial hints, changelog entries, and any content that should stay out of the way until the user asks for it.
Wrap hidden content in details and add a summary as the first child:
<details>
<summary>Click to expand</summary>
<p>Hidden content goes here.</p>
</details><summary> should be the first child inside details.open, content starts hidden until the user toggles it.name on multiple widgets for accordion-style exclusive panels.| Feature | Syntax / Rule | Notes |
|---|---|---|
| open | open | Expanded on page load |
| name | name="group" | Accordion group behavior |
| Default state | Closed | Unless open is present |
| Pairs with | <summary> | Visible clickable label |
| JavaScript | Not required | Native toggle behavior |
| Use cases | FAQ, specs | Hints, optional info |
<details> and <summary>These elements work together to create a native disclosure widget:
| Element | Role | Notes |
|---|---|---|
<details> | Container | Holds the collapsible content |
<summary> | Label | Clickable heading users see |
| Order | summary first | Best practice for accessibility |
| Without summary | Fallback label | Browser shows a default label |
The main tag-specific attributes are open and name:
open BooleanWhen present, the widget starts expanded on page load.
<details open>name OptionalGroups multiple details elements. Opening one may close others with the same name.
name="faq"class GlobalCSS hook for custom disclosure styling.
class="faq-item"id GlobalUnique identifier for linking or scripting.
id="shipping-info"open keeps the panel expanded initially. name groups multiple details elements so opening one may close others with the same name.
Basic disclosures, open-by-default panels, FAQ sections, and accordion groups with copy-ready code and live previews.
Click the summary to toggle the hidden paragraph:
HTML structures content on the web using elements like headings, paragraphs, and links.
A simple collapsible block with summary.
<details>
<summary>Click to reveal more info</summary>
<p>This hidden content appears when opened.</p>
</details>Use <details> for FAQ answers, optional product specs, tutorial hints, changelog entries, and any content that should stay out of the way until the user asks for it.
Add the open attribute to show content expanded on load.
<details open>
<summary>Shipping information</summary>
<p>Orders ship within 2 business days.</p>
</details>Stack multiple details blocks for questions and answers.
<details>
<summary>How do I reset my password?</summary>
<p>Go to Settings and follow the reset link sent to your email.</p>
</details>
<details>
<summary>Can I cancel my subscription?</summary>
<p>Yes. Open Billing and select Cancel Plan.</p>
</details>Share a name value so only one panel stays open at a time.
<details name="plan" open>
<summary>Free plan</summary>
<p>Basic lessons and community access.</p>
</details>
<details name="plan">
<summary>Pro plan</summary>
<p>All courses and certificates.</p>
</details>Browsers provide default disclosure styling. Customize borders, markers, and open states for a polished look:
border Card-style panelssummary Custom label styling::marker Hide default triangle[open] Style expanded state/* Disclosure widget styling */
details {
padding: 0.75rem 1rem;
background: #fff;
border: 1px solid #e2e8f0;
border-radius: 8px;
}
details summary {
cursor: pointer;
font-weight: 600;
color: #1e40af;
}
details[open] summary {
margin-bottom: 0.5rem;
}Live styled disclosure
Orders ship within 2 business days via standard delivery.
Native disclosure widgets include built-in keyboard support:
summary is the label; other children are hidden content.
Only the summary shows unless open is set.
Click or keyboard activates summary to reveal content.
Optional content stays hidden until the user needs it—no script required.
The <details> element is fully supported in all modern browsers. Internet Explorer does not support it.
Chrome, Firefox, Safari, Edge, and Opera all support native disclosure widgets. Provide a JavaScript fallback for legacy IE environments.
Bottom line: Safe for all modern production environments. For legacy IE, provide a JavaScript accordion fallback or show content expanded by default.
The <details> tag is a simple way to add collapsible sections without JavaScript. Pair it with summary, use open when content should start visible, and group panels with name for accordion behavior.
summary labelname for exclusive accordions<details>Bookmark these before you ship — they’ll keep your disclosure widgets semantic and accessible.
<details> creates a native collapsible section.
The clickable heading users see before expanding.
EssentialStarts the widget expanded on page load.
SyntaxGroups panels for exclusive accordion behavior.
PatternBrowsers handle toggle behavior natively.
BehaviorProvide a fallback for legacy environments.
Compatsummary for the visible heading.summary.details widget expanded when the page loads. Without it, content starts hidden.summary provides the clickable label. Place it as the first child inside details.details elements share the same name, opening one can close the others—useful for accordion groups.Practice details, summary, and accordion patterns in the interactive HTML editor.
6 people found this page helpful