The <summary>
tag in HTML is used in conjunction with the <details>
tag to provide a visible heading or summary for a collapsible content section. It allows users to toggle the visibility of additional content by clicking on the summary element. This is useful for creating interactive and expandable content sections, such as FAQ sections, where users can click to reveal more details.
<details>
tag to show or hide additional content when the summary is clicked.<details>
<summary>Click to expand</summary>
<p>This is the additional content that will be revealed when the summary is clicked.</p>
</details>
In this example:
<summary>
tag contains the text "Click to expand," which serves as a heading or label for the collapsible section.<details>
tag wraps both the <summary>
and the additional content. Clicking on the summary reveals or hides the content.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Summary Tag Example</title>
<style>
details {
margin-bottom: 10px;
}
summary {
font-weight: bold;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Frequently Asked Questions</h1>
<details>
<summary>What is HTML?</summary>
<p>HTML stands for HyperText Markup Language. It is the standard language used to create and design webpages.</p>
</details>
<details>
<summary>What is CSS?</summary>
<p>CSS stands for Cascading Style Sheets. It is used to describe the presentation and layout of HTML elements on a webpage.</p>
</details>
<details>
<summary>What is JavaScript?</summary>
<p>JavaScript is a programming language that enables interactive features and dynamic content on webpages.</p>
</details>
</body>
</html>
In this example:
<details>
element contains a <summary>
tag and additional content.open
: A boolean attribute that, if present, keeps the <details>
element expanded by default.
<details open>
<summary>Default Open</summary>
<p>This section is expanded by default.</p>
</details>
<summary>
to assist screen readers and other assistive technologies.<summary>
tag provides a heading or label for a collapsible section defined by the <details>
tag.open
attribute can be used to keep the details expanded by default.In summary, the <summary>
tag in HTML, when used within a <details>
element, helps create interactive and collapsible content sections. It provides a summary or heading that users can click to reveal or hide additional content, enhancing the usability and organization of the webpage.
@aCodeTutorials All Rights Reserved
privacy policy | about