Using the HTML `<summary>` Element to Label `` Widgets: Creating Interactive Collapsible Content
Learn how to use the HTML `<summary>` element to create a visible label for `
Using the HTML `<summary>` Element to Label `` Widgets
Understanding the `<summary>` Element
The HTML `<summary>` element is used to create a visible heading or label for an HTML `
Using the `<summary>` Element
To create an interactive widget with a visible label, place the label text within the `<summary>` tags, and place the content to be revealed or hidden within the `
Example: Basic `<summary>` and ``
<details>
<summary>Click me to see details</summary>
<p>This text is hidden until you click the summary.</p>
</details>
Clicking the summary text ("Click me...") will toggle the visibility of the paragraph.
Browser Support for `<summary>`
The `<summary>` element is supported by major modern browsers. Check the W3Schools Browser Support page for a complete reference.
Browser | Version |
---|---|
Chrome | 12.0 |
Edge | 79.0 |
Firefox | 49.0 |
Opera | 6.0 |
Safari | 15.0 |
Styling `<summary>` with CSS
You can customize the appearance of the summary using CSS. For example:
Example: Styling `<summary>` with CSS
summary {
font-weight: bold;
cursor: pointer;
}
Most browsers render the `<summary>` element as a block-level element by default.