Ask any question about HTML here... and get an instant response.
How can I create a collapsible section in my webpage?
Asked on Nov 09, 2025
Answer
To create a collapsible section in your webpage, you can use the HTML
and elements. This provides a simple way to hide and reveal content without needing JavaScript.
elements. This provides a simple way to hide and reveal content without needing JavaScript.
<!-- BEGIN COPY / PASTE -->
<details>
<summary>Click to expand</summary>
<p>This is the content that can be collapsed or expanded.</p>
</details>
<!-- END COPY / PASTE -->
Additional Comment:
- The
<details> element creates a widget that users can open and close.
- The
<summary> element acts as a label for the <details> element and is always visible.
- Content inside the
<details> element is hidden by default and shown when the user clicks the <summary>.
✅ Answered with HTML best practices.
<!-- BEGIN COPY / PASTE -->
<details>
<summary>Click to expand</summary>
<p>This is the content that can be collapsed or expanded.</p>
</details>
<!-- END COPY / PASTE -->Additional Comment:
- The
<details>element creates a widget that users can open and close. - The
<summary>element acts as a label for the<details>element and is always visible. - Content inside the
<details>element is hidden by default and shown when the user clicks the<summary>.
✅ Answered with HTML best practices.
Recommended Links:
