Amazing Science

How to make a dropdown menu using <details> tag

Dropdown menu is a good design choice because it saves lot of space on a webpage. When it comes to displaying mega menu with many sub menus, dropdown proves to be a good choice especially for mobile screen.

Dropdown menu with HTML and CSS but no Javascript

Javascript is a good tool to add interactivity to user interface. But many web developers may want to avoid javascript. CSS can also be used to add interactivity to UX elements.

Using details Tag to make a dropdown menu

Dropdown Menu
Dropdown Menu

The details tag gives a fair amount of interactivity without the use of javascript. This tag is mainly used for showing some hidden content at a click of a button like display within the details tag. So, the details tag is similar to dropdown in terms of appearance and functionality. Let us make a dropdown menu using details and summary tags in html.

Making the Skeleton of Dropdown Menu

Following is the html for my dropdown menu.

Dropdown Menu HTML code
Dropdown Menu HTML

Steps

At present the page is without a style. When you will view it in browser, it will look like this picture.

Dropdown Menu
Dropdown Menu Display without style

Add CSS

Now the skeleton is ready, you need to make it look beautiful. Let us add some CSS to create a nice look.

Steps

Dropdown Menu CSS
Dropdown Menu CSS
Dropdown Menu CSS
Dropdown Menu CSS
Dropdown Menu CSS
Dropdown Menu CSS

Now, as the style part is over, you can refresh the page to see its new look. It will look like the following picture.

Dropdown Menu
Dropdown Menu Display with style

You can view this demo on Codepen