- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- 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 - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- 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 Code Builder
- HTML References
- 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
The 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 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.
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
Following is the syntax of the <summary> tag −
<summary>.....</summary>
Example
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> Lorem, ipsum dolor sit amet consectetur adipisicing elit. Iure velit harum dicta minus provident reiciendis obcaecati aut voluptatem repellat, dignissimos architecto ea ab non eligendi sed. Cum ipsum autem alias. </details> </body> </html>
When we run the above code, it will generate an output consisting of the text along with a dropdown menu. When the user, click on that menu, it displays its internal text.
Example
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>
On running the above code, the output window will pop up, consisting of the text along with a dropdown menu text displayed as soon as the page loads.
Example
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; font-style: italic; height: 30px; border: 1px solid black; border-radius: 10px; text-align: center; align-items: center; justify-content: center; background-color: green; cursor: pointer; } </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>
When we run the above code, it will generate an output consisting of the text along with a dropdown menu applied with the CSS diplayed on the webpage
Example
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>
When we run the above code, it will generate an output consisting of the text along with a two dropdown menu applied with the CSS diplayed on the webpage
To Continue Learning Please Login
Login with Google