- HTML Tutorial
- HTML - Home
- HTML - Introduction
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Headings
- HTML - Paragraphs
- HTML - Fonts
- HTML - Blocks
- HTML - Style Sheet
- HTML - Formatting
- HTML - Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <summary> Tag
HTML <summary> tag is used to specify the summary, caption, or legend for the details element disclosure box.
It is used within the details element. When a user clicks on the <summary>, it toggles the states of the parent element <details> open and closed. The <summary> element content can be any heading content, plain text, or HTML that can be used within a paragraph.
The default toggle state is closed(either you use the close attribute or not). You can also change the style to display: block to remove the disclosure triangle.
Syntax
<summary>.....</summary>
Attribute
HTML summary tag supports Global and Event attributes of HTML.
Examples of HTML summary Tag
Bellow examples will illustrate the usage of summary tag. Where, when and how to use summary tag.
Implementing summary Element
The following example is showing the uses of the HTML <summary> tag within a ‘details’ element.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML summary tag</title> </head> <body> <!--create a summary tag--> <p>HTML 'summary' element example..</p> <details> <summary>Read more</summary> It is used within the details element. When a user clicked on the summary, it toggles the states of the parent element details open and closed. The summary element content can be any heading content, plain text, or HTML that can be used within a paragraph. </details> </body> </html>
Summary in List Form
Following is another example of the HTML <summary> tag. Here, we are using the <summary> tag inside a <details></details> element to specify the summary for it. Then, we are creating HTML list, when the user clicks on the summary list will be displayed.
But, we use the 'open' attribute in the 'details' element, so by default, it will open.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML summary tag</title> </head> <body> <!--create a summary tag--> <p>HTML 'summary' element example..</p> <details open> <summary>Overview</summary> <ul> <li>Total money : 5000</li> <li>Cash on hand : 3570 </li> <li>Spended money : (5000 - 3570) = 1430</li> </ul> </details> </body> </html>
Styling summary Element
In this example, we are using the HTML <summary> tag to specify the ‘summary’ for the ‘details’ element disclosure box. We are using CSS to style the created ‘summary’ element.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML summary tag</title> <style> summary { width: 100px; color: white; height: 30px; border: 2px solid black; border-radius: 5px; text-align: center; justify-content: center; background-color: green; cursor: pointer; padding-top: 10px } </style> </head> <body> <!--create a summary tag--> <p>HTML 'summary' element example..</p> <details> <summary>Click me!</summary> <p>You clicked on click me!</p> </body> </html>
Nested summary Element
Let's look at the another scenario , where we are going to takemultiple or nested <summary> tag.
<!DOCTYPE html> <html lang="en"> <head> <title>HTML summary tag</title> <style> summary:nth-child(1) { color: red; } </style> </head> <body> <!--create a summary tag--> <p>HTML 'summary' element example..</p> <details open> <summary>Click me!</summary> <p>Because of 'open' attribute its opened(by default)</p> <details> <summary>click me again!</summary> <p>You clicked on 'click me again!'</p> </details> </body> </html>
Supported Browsers
Tag | |||||
---|---|---|---|---|---|
embed | Yes 12.0 | Yes 79.0 | Yes 49.0 | Yes 6.0 | Yes 15.0 |
To Continue Learning Please Login
Login with Google