You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<title>Modern Accordion and FAQs Component Using "details" and "summary" (No JavaScript)</title>
8
+
</head>
9
+
<body>
10
+
<main>
11
+
<h1>Example of Accordion Components and FAQs without using JavaScript</h1>
12
+
<!-- Example of correct usage of <details> and <summary> -->
13
+
<detailsopenname="example">
14
+
<summary>Description</summary>
15
+
<p>
16
+
With the new <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details" target="_blank">"details"</a> and <ahref="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/summary" target="_blank">"summary"</a> element tags, it has become simpler, more semantic, and accessible to develop an Accordion and FAQs (Frequently Asked Questions) component without using JavaScript.
17
+
</p>
18
+
</details>
19
+
<!-- In this example, the "open" attribute does not work as expected, as explained below -->
20
+
<detailsopenname="example">
21
+
<summary>Attributes</summary>
22
+
<dl>
23
+
<dt>Open</dt>
24
+
<dd>This is a boolean attribute that, when declared on the <code><details></code> element, displays the content inside the <code><details></code>. When not present, it hides the content. By default, this attribute is absent and does not display the "details".
25
+
<br/>
26
+
You can use this attribute on more than one <code><details></code> element at a time, but when the <code>name="example"</code> attribute values are the same across <code><details></code> elements, it only works for the first element with the attribute declared.
27
+
</dd>
28
+
<dt>Name</dt>
29
+
<dd>This attribute groups several <code><details></code> elements, allowing only one of them to be opened at a time. This functionality makes the UI and component behave similarly to an accordion.</dd>
30
+
</dl>
31
+
</details>
32
+
<!-- Example of using more than one "open" attribute but without relation to the "name" attribute, and also an element nested within another -->
33
+
<detailsopen>
34
+
<summary>FAQs</summary>
35
+
<ul>
36
+
<li>Question 1</li>
37
+
<li>Question 2</li>
38
+
<li>Question 3</li>
39
+
</ul>
40
+
<details>
41
+
<summaryclass="toggle">Answer</summary>
42
+
<pclass="answer">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ab doloribus magni dolorum fugiat maxime corrupti suscipit officiis sequi. Porro nesciunt, amet magnam aliquid odio eaque non est rerum labore ducimus!</p>
0 commit comments