Personally I consider that HTML is the most important markup language on the entire internet, when you open any web page I assure you that its structure is written in HTML.
Many may assume that HTML is not that important but it is the basis of the entire modern web and for this reason it has always been evolving, from new APIs that we can use to simpler but important features to know.
Accordions in HTML are written using the details tag and nesting summary tags to represent each accordion.
Before dedicated accordions it was not possible for the behavior of each accordion to be independent using only native HTML, this means that multiple accordions could be open at the same time. Let's look at an example:
In this example we can notice that the accordions can be open at the same time which is the default behavior.
Since September 2024, the novelty is that we can create exclusive accordions natively without using any JavaScript.
A unique accordion allows only one summary tag to be open, improving the UI without having to write JS code to achieve this.
To achieve this, simply add the name attribute with the same value to each summary tag.
Let's look at an example:
In our example each summary has name="learn-css" which allows the accordion to be exclusive.
We can find that this functionality is available from the following browser versions:
And by consulting Can I Use we verified the same, having 89.13% of the browsers covered as of the date of publication of this post.
It is very important to be up to date with the latest developments in the tools we use the most, these new features can save us more than once by making our work easier.
I leave you a summary post on my twitter account:
Other posts of my authorship that may interest you:
The above is the detailed content of Exclusive native accordions in HTML�. For more information, please follow other related articles on the PHP Chinese website!