The summary HTML element provides a brief explanation or summary of the content that follows it. It is typically used within list items (li) or section elements (section) to provide additional context or information about the contained content. The summary tag should be accompanied by a details tag, which provides the full details or description when clicked or expanded.
<section>
<h2>My Favorite Things</h2>
<ul>
<li>
<details>
<summary>Movies:</summary>
<ul>
<li>The Shawshank Redemption</li>
<li>The Godfather</li>
<li>Forrest Gump</li>
</ul>
</details>
</li>
<li>
<details>
<summary>Music:</summary>
<ul>
<li>Beethoven's Symphony No. 9</li>
<li>The Beatles' Abbey Road</li>
<li>Michael Jackson's Thriller</li>
</ul>
</details>
</li>
</ul>
</section>
In this example, the summary tag provides a summary of the content within each list item. When the user clicks on the “Movies” or “Music” text, the details section will expand and display the full list of movies or music.
Attributes Applicable to the Summary Tag
Here are some of the attributes that can be applied to the summary tag:
open
– This attribute specifies whether thehidden
– This attribute hides the entire tag, as it can prevent users from accessing important information.