Native Accordions Are about to Land in Chrome
Write an accordion with the native HTML details element
Accordions are a pattern that is implemented by every big UI library (such as Material UI or Bootstrap). They are pretty standardized; if you use one of them, you should notice that they come with tab navigation and that you can open each individual item by pressing space. This contributes to the accessibility of the element. However, not every library meets these accessibility standards (Ant Design, for instance).
Finally, accordions make it to the native web, and we get rid of many obstacles we face today.
The details element
The HTML details element is the core of native accordions. Let’s take a look:
<details>
<summary>Label</summary>
<div>
Text
</div>
</details>This will render an element that roughly looks like this:

The element is closed by default (there’s an open attribute). In its closed state, it will only display the contents of the summary.
Now, if we put two of these elements next to each other, they will work independently. Meaning, I can open both at the same time:

This behavior works across all modern web browsers.
Add the accordion behavior to the details element
But, of course, we are not there yet. The desired behavior would be to open these elements exclusively. Meaning only one of the items can be opened at the same time.
We can reach our goal by using the name attribute, very much like a group of radio buttons:
<details name="accordion-1">
<summary>Label 1</summary>
<div>
Text 1
</div>
</details>
<details name="accordion-1">
<summary>Label 2</summary>
<div>
Text 2
</div>
</details>Now, these details elements are grouped, and we achieved the desired effect. But, unfortunately …

Anyways, if you are using the current version of Google Chrome, here’s a fiddle for you to play with:






