HTML <summary> Tag โ Clickable Title for Details
๐ Introduction
The <summary> tag defines the visible heading of a <details> element.
It is the part users click to expand or collapse hidden content.
๐ It only works inside <details>.
๐งฑ Syntax
<details>
<summary>Click to show more</summary>
Hidden content here
</details>
๐ก Example
<!DOCTYPE html>
<html>
<head>
<title>Summary Example</title>
</head>
<body>
<h2>FAQ</h2>
<details>
<summary>What is HTML?</summary>
HTML is the structure of web pages.
</details>
<details>
<summary>What is CSS?</summary>
CSS is used for styling web pages.
</details>
</body>
</html>
๐ฅ๏ธ Output Explanation
- The
<summary>is visible first - Clicking it expands the hidden content
- Works like a built-in dropdown
๐ฏ Why <summary> is Important
1. ๐ง Controls <details>
Without <summary>, the details section has no clickable title.
2. ๐ฑ Improves UX
Users can expand only what they need.
3. โก No JavaScript Needed
Works natively in HTML.
๐งฉ How It Works
<summary>
โ click โ show/hide
<details>content</details>
</summary>
๐จ Styling Example
<summary style="font-weight:bold; cursor:pointer;">More Info</summary>
โ๏ธ <summary> vs <details>
| Tag | Role |
|---|---|
<details> |
Container (hidden content) |
<summary> |
Clickable title |
๐ซ Common Mistakes
- Using
<summary>outside<details>โ - Forgetting
<summary>inside<details>โ - Putting too much text in summary โ
๐งช Mini Exercise
Create a page with:
- 3
<details>elements - Each has a
<summary>question - Add answers below
- Style the summary text to look clickable