Multiple elements were introduced in HTML5 that are not yet widely known; one of them allows you to create interactive experiences such as accordions or dropdowns, the name of this element is <details>.
The <details> element allows us to implement a disclosure widget that hides and shows information depending on its boolean state open. This allows us to toggle content interactively and natively:
<detailsclass="details-example"><summary>If you click me I will display a list of content</summary><ul><li>Option 1</li><li>Option 2</li><li>Option 3</li></ul></details>
Demo
If you click me I will display a list of content
Option 1
Option 2
Option 3
As you can see, the <summary> shows up, and when clicking it, we are showing the rest of the information (the list of options).
We are able to achieve this with just HTML, I am adding some CSS to style the dropdown but only styles.
Extra tip (Javascript integration)
You can also execute complementary javascript when the open state of the details element changes, we can do that like this:
Very simple yet powerful feature, some of its more notorious applications are for accordions, dropdowns and toggling visual content in general. Companies such as github use it for their menus and interactions, hopefully now you will also be able to delete some javascript in your code base and use a native HTML element instead.
Big O notation allows us to evaluate the performance of algorithms so that we can determine their efficiency and make decisions based on this determinations, let's try to understand how this notation works and how we can apply it in our lives as software developers.Read more
Linked Lists are a fundamental data structure in the world of software development, in this article we will explore its implementation and its applications in today's worldRead more