The HTML <details> element creates a native disclosure widget that users can open and close. Put a <summary> first inside it to provide the visible label. For basic expandable content, no JavaScript is required.
This pattern is useful for optional explanations, troubleshooting steps, FAQs, technical notes, and other secondary content that should remain available without taking up space by default.
<details>
<summary>More information</summary>
<p>This content appears when the section is opened.</p>
</details>
This content appears when the section is opened.
Click or keyboard-activate the summary to toggle the section. Keep the summary short and descriptive so users know what will be revealed.
<details> contains the disclosure label and the content that can be shown or hidden.<summary> should be the first child of <details> and acts as the visible control.open is absent, only the summary is normally visible.open is present, the additional content is shown.Add the Boolean open attribute when the disclosure should start expanded.
<details open>
<summary>Shipping information</summary>
<p>Orders are dispatched after processing.</p>
</details>
Because open is Boolean, writing open="false" still makes the section open. Remove the attribute completely when it should start closed.
Each <details> element works independently by default, so users can keep several sections open at the same time.
<details>
<summary>HTML</summary>
<p>HTML provides the structure of a web page.</p>
</details>
<details>
<summary>CSS</summary>
<p>CSS controls presentation and layout.</p>
</details>
HTML provides the structure of a web page.
CSS controls presentation and layout.
Give several <details> elements the same name value when you want only one section in that group to remain open at a time. This creates a simple accordion without JavaScript.
<details name="course">
<summary>HTML</summary>
<p>Learn page structure and semantic elements.</p>
</details>
<details name="course">
<summary>JavaScript</summary>
<p>Learn browser-side scripting and events.</p>
</details>
Learn page structure and semantic elements.
Learn browser-side scripting and events.
The basic disclosure behavior has broad browser support. The grouped name behavior is newer, so test it if your project must support older browser versions.
You can style the container, summary label, and open state with CSS while keeping the native interaction.
details {
border: 1px solid #ccc;
border-radius: 6px;
padding: 0.75rem;
}
summary {
font-weight: 600;
cursor: pointer;
}
details[open] summary {
margin-bottom: 0.5rem;
}
Avoid removing the disclosure marker unless you provide an equally clear visual indication that the summary can be expanded and collapsed.
JavaScript is not required for normal disclosure behavior. Add it only when your application needs to react to state changes. A toggle event is fired after a <details> element opens or closes.
const details = document.querySelector('#help');
details.addEventListener('toggle', () => {
console.log(details.open ? 'Open' : 'Closed');
});
For more event-handling concepts, see the JavaScript events tutorial.
<summary> label instead of vague text such as “Click here”.<div> or clickable text.<details> and <summary>; their built-in semantics should normally be preserved.Do not use disclosure widgets simply to hide large amounts of weak or repetitive content. The decision should improve usability for the reader.
Use <details> because it improves the user's experience, not as an SEO technique. Important introductory answers should still be easy to find, while secondary explanations can be placed in expandable sections when that organization genuinely helps readers.
The visible heading, summary text, surrounding context, and quality of the concealed content should all remain descriptive and useful. Do not put the entire purpose of a page behind a disclosure control.
<summary> label.open="false" and expecting the section to be closed.No. Browsers provide the standard open-and-close interaction natively. JavaScript is only needed for extra behavior.
It provides the visible label or caption that users activate to open or close the parent <details> element.
Add the Boolean open attribute to the <details> start tag.
Yes. In current browsers, multiple <details> elements with the same name value can form a group where opening one closes the previously open item.
Yes. You can style the container, summary, open state, and disclosure marker, but preserve a clear interactive cue and keyboard usability.
HTML5 tags | HTML dialog element | Types of HTML tags
HTML5 Tags Types of HTML tagsAuthor & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.