Member-only story

Dropdown Lists Without CSS or JS

Using the browser-native <details> element

Alex Z
2 min readMar 21, 2022
source: dev.to

The <details> element in HTML creates a “dropdown list” section of text content. It generates a “toggle” arrow allowing the hidden text within the component to be shown or hidden.

This element is semantic (meaning it is easily understood by web crawlers) and supported by all major browsers. It works without the use of any additional CSS or JS (though both can be added for extra features if needed).

It also allows you to support nested dropdowns without any extra work, something that can be hassle if you want to create your own implementation of this feature. View a demo here.

If you come across a situation in which you need to create either a simple or complex dropdown with this basic format, do not use a <div> and add custom CSS + JS, unless absolutely necessary. The HTML specification already has this case covered!

Thanks for reading, and for taking a step toward becoming a better HTML Author.

If you like this post, consider becoming a member to support writers like myself on Medium!

Sources:

  1. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details

--

--

Alex Z
Alex Z

Written by Alex Z

Software Developer + Product Manager. Interested in Travel, Culture, Economics and the Internet. Join Medium: https://tinycode.medium.com/membership

Responses (1)