Copied successfully!
Introduction to <details>
tag
The <details>tag in HTML is an interactive element that allows developers to create expandable and collapsible content. This tag is particularly useful for hiding content that is not immediately necessary to display, thereby enhancing the user experience by keeping the webpage clean and organized. When a user clicks on the <details>element, it toggles between showing and hiding the content within it.
Key Features of the <details>
Tag
Interactive Disclosure: The <details>tag provides a built-in mechanism for users to interact with the content. By default, it is displayed as a disclosure widget, which is typically a triangle or an arrow, indicating that the content can be expanded or collapsed.
Nested Content: The content inside the <details>tag can be any valid HTML element, including paragraphs, images, lists, and even other interactive elements. This flexibility allows developers to use the <details>tag in various contexts, such as FAQs, terms and conditions, or additional information sections.
Accessibility: The <details>tag is designed to be accessible. It is fully supported by screen readers and can be navigated using keyboard controls, ensuring that all users, including those with disabilities, can interact with the content.
Styling and Customization: While the default appearance of the <details>tag is simple, it can be styled using CSS to match the design of the webpage. Developers can customize the appearance of the disclosure widget and the expanded content to create a more cohesive and visually appealing user experience.
Copy to clipboard
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Interactive FAQ with Details Tag</title>
<link rel="stylesheet" href="styles.css"> <!-- Link to external CSS file -->
</head>
<body>
<div class="container">
<h1>Frequently Asked Questions</h1>
<!-- FAQ 1 -->
<details class="faq-item">
<summary>What is the return policy?</summary>
<p>Our return policy lasts 30 days. If 30 days have passed since your purchase, unfortunately, we can’t offer you a refund or exchange.</p>
</details>
<!-- FAQ 2 -->
<details class="faq-item">
<summary>How do I track my order?</summary>
<p>You can track your order using the tracking number provided in the confirmation email or by logging into your account on our website.</p>
</details>
<!-- FAQ 3 -->
<details class="faq-item">
<summary>Do you ship internationally?</summary>
<p>Yes, we offer international shipping to most countries. Shipping rates and delivery times will vary based on the destination.</p>
</details>
<!-- FAQ 4 -->
<details class="faq-item">
<summary>How can I contact customer service?</summary>
<p>You can contact our customer service team via the contact form on our website or by calling our toll-free number: 1-800-123-4567.</p>
</details>
</div>
</body>
</html>
Copy to clipboard
/* General Styles */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f0f4f8; /* Subtle light blue-gray background */
color: #333;
margin: 0;
padding: 20px;
}
.container {
max-width: 800px;
margin: 0 auto;
background-color: #fff;
padding: 30px;
border-radius: 12px; /* More rounded corners for the container */
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1); /* Enhanced shadow for depth */
transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out; /* Smooth transition for hover effects */
}
/* Hover effect for container */
.container:hover {
transform: translateY(-5px); /* Slight lift on hover */
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15); /* More pronounced shadow on hover */
}
h1 {
text-align: center;
color: #0056b3; /* Slightly darker blue for the heading */
margin-bottom: 25px;
font-size: 2.4em; /* Larger font size for the heading */
background: linear-gradient(to right, #6a11cb, #2575fc); /* Gradient text */
-webkit-background-clip: text;
color: transparent;
}
/* Details and Summary Styles */
.faq-item {
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 8px;
overflow: hidden;
transition: background-color 0.3s ease; /* Smooth transition for background color */
}
/* Hover effect for FAQ item */
.faq-item:hover {
background-color: #f1f5f9; /* Light background on hover */
}
.faq-item summary {
cursor: pointer;
padding: 20px; /* More padding for a spacious feel */
background-color: #f7f9fc; /* Light blue-gray background */
font-size: 1.2em;
font-weight: bold;
position: relative;
list-style: none;
transition: background-color 0.3s ease, color 0.3s ease; /* Smooth transition for color changes */
border-bottom: 1px solid #eee; /* Subtle border below summary */
}
/* Hover and active states for summary */
.faq-item summary:hover {
background-color: #eaf2f8; /* Slightly darker background on hover */
}
.faq-item[open] summary {
background-color: #6b42ff; /* Blue background when expanded */
color: #fff; /* White text when expanded */
}
/* Custom Icon for Summary */
.faq-item summary::before {
content: '➕'; /* Plus icon for closed state */
font-size: 1.4em; /* Larger font size for the icon */
color: #0056b3; /* Blue color for the icon */
position: absolute;
right: 20px;
transition: transform 0.3s ease, color 0.3s ease; /* Smooth transition for icon rotation and color */
}
/* Rotate and change icon color when open */
.faq-item[open] summary::before {
content: '➖'; /* Minus icon for open state */
transform: rotate(180deg); /* Rotate icon on open */
color: #fff; /* White color for the icon when open */
}
/* Details Content Styles */
.faq-item p {
padding: 20px; /* More padding for content */
margin: 0;
background-image: linear-gradient(to right, rgb(225, 246, 255), #ffd2fd);
color: #333;
border-top: 1px solid #ddd;
font-size: 1em;
animation: slideDown 0.4s ease-in-out; /* Slide down animation for opening content */
}
/* Keyframes for slide down animation */
@keyframes slideDown {
0% {
opacity: 0;
transform: translateY(-10px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
/* Responsive Design */
@media (max-width: 600px) {
.container {
padding: 20px;
}
.faq-item summary {
font-size: 1.1em;
}
.faq-item p {
font-size: 0.95em;
}
}
Global Attributes
Attributes | Description |
---|---|
accesskey | Specifies a shortcut key to activate or focus an element. |
autocapitalize | Controls whether and how text input is automatically capitalized. |
class | Specifies one or more class names for the element, allowing CSS styling and JavaScript manipulation. |
contenteditable | Specifies whether the content of an element is editable or not. |
contextmenu | Specifies a context menu for the element. |
dir | Defines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto". |
draggable | Specifies whether an element is draggable. Possible values are "true" or "false". |
enterkeyhint | Specifies the action label or icon to be shown for the enter key on virtual keyboards. |
hidden | Indicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set. |
id | Specifies a unique identifier for the element. |
inputmode | Provides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants. |
is | Allows you to specify the type of custom element. |
lang | Specifies the language of the element's content. |
nonce | A cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed. |
part | Specifies the element’s part in the shadow DOM. |
slot | Assigns a slot in a shadow DOM shadow tree. |
spellcheck | Indicates whether the element is subject to spell checking. |
style | Provides inline CSS styling for the element. |
tabindex | Specifies the tab order of the element. |
title | Adds extra information about the element, displayed as a tooltip when hovering over the element. |
translate | Specifies whether the content of the element should be translated. Possible values are "yes" or "no". |
HTML Attributes | Global Attributes | Event Attributes |
---|---|---|
To view the full list | To view the full list | To view the full list |
elements | |||||
---|---|---|---|---|---|
<details> | 12.0 | 79.0 | 49.0 | 6.0 | 15.0 |
Improve Our Platform
Did you find what you were looking for?
Learn how to contribute.Last updated on by our contributors.
View this page on GitHub• Report an issue with this content