Learn HTML – Part 53 – details Tag – Expandable Content
The HTML details tag is used to create expandable and collapsible content sections.
Users can click to show or hide additional information.
What is the details Tag?
The details element creates a disclosure widget where content can be expanded or collapsed.
It is commonly used for FAQs, additional information, and hidden content sections.
Basic Syntax
<details>
<summary>Click to expand</summary>
Hidden content here
</details>
Example – Simple Expandable Content
<details>
<summary>What is HTML?</summary>
HTML stands for HyperText Markup Language.
</details>
Output:
What is HTML?
HTML stands for HyperText Markup Language.
What is the summary Tag?
The summary tag defines the visible heading of the details element.
Users click the summary to toggle the content.
Example – FAQ Section
<details>
<summary>What is CSS?</summary>
CSS is used to style HTML elements.
</details>
<details>
<summary>What is JavaScript?</summary>
JavaScript is used to make web pages interactive.
</details>
Output:
What is CSS?
CSS is used to style HTML elements.
What is JavaScript?
JavaScript is used to make web pages interactive.
Open Attribute
The open attribute makes the content visible by default.
<details open>
<summary>Visible by default</summary>
This content is already expanded.
</details>
Output:
Visible by default
This content is already expanded.
Why Use details?
- Creates interactive expandable sections
- Improves user experience
- Reduces page clutter
- Commonly used for FAQs
The
detailstag creates expandable content sections that users can toggle.
Common Mistakes Beginners Make
- Not using the
summarytag inside details - Placing too much content inside a single details element
- Expecting advanced styling without CSS
Conclusion
The HTML details tag is used to create expandable and collapsible content sections.
It is a simple way to improve interactivity without using JavaScript.
What’s Next?
Now that you understand the details tag, the next step is learning about the summary tag, which defines the heading for expandable content.
Next: Learn HTML – Part 54 – summary Tag – Details Caption →
Series: Learn HTML Series
