How to make a dropdown menu in HTML
The two kinds of dropdown: a <select> list people pick from in a form, and a menu that opens under a navigation link. Code for both, a placeholder option, option groups, a type-ahead list, and why a hover menu fails on phones.
Have the file already? Upload it and get a link anyone can open. Free plan, no card.
Get a link free"Dropdown" means two different things in HTML. A select list is a form field where someone picks one option, like a country or a meal choice. A dropdown menu is a set of links that opens under a navigation item. Each has its own code.
A select list (form dropdown)
Use the <select> tag with one <option> per choice:
<label for="size">Size</label> <select id="size" name="size"> <option value="s">Small</option> <option value="m">Medium</option> <option value="l">Large</option> </select>
The text between the option tags is what people see; the value attribute is what the form sends. If an option has no value, the form sends its text. The label with a matching for and id lets people click the word Size to open the list, and screen readers read it out.
Placeholder, default and required
- ✓Placeholder: make the first option empty and unselectable: <option value="" disabled selected>Choose a size</option>.
- ✓Default: add selected to the option that should show first, such as <option value="m" selected>Medium</option>.
- ✓Required: add required to the <select>. With the empty placeholder above, the form will not submit until someone picks a real option.
- ✓Disabled: add disabled to a single option to show it greyed out, for example a sold-out size.
Group options and allow several picks
- ✓Groups: wrap options in <optgroup label="Fruit">…</optgroup>. The label shows as a bold heading that cannot be picked.
- ✓Several picks: add multiple to the <select>. It turns into a box where people hold Ctrl (Cmd on a Mac) to pick more than one; on phones it becomes a checklist. For three or four choices, checkboxes are easier to use.
- ✓Type to search: for a long list, <input list="cities" name="city"> with <datalist id="cities"><option value="Austin"><option value="Boston"></datalist> shows suggestions as people type, and still lets them type something not on the list.
A navigation dropdown with no JavaScript
The simplest menu that opens on click uses <details> and <summary>:
<details class="menu"> <summary>Services</summary> <a href="design.html">Design</a> <a href="hosting.html">Hosting</a> </details>
Clicking Services shows the links; clicking again hides them. It works with a mouse, a keyboard (Tab to it, press Enter) and a finger on a phone. Add .menu a { display: block; } so each link sits on its own line, and .menu { position: relative; } with position: absolute on the inner links if you want the list to float over the page instead of pushing it down.
A dropdown that opens on hover
Wrap the item and its links in one element and show the links when the pointer is over it:
<style> .dd { position: relative; display: inline-block; } .dd-links { display: none; position: absolute; top: 100%; left: 0; min-width: 160px; background: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.15); z-index: 10; } .dd-links a { display: block; padding: 8px 12px; } .dd:hover .dd-links, .dd:focus-within .dd-links { display: block; } </style>
<div class="dd"> <a href="#">Services</a> <div class="dd-links"> <a href="design.html">Design</a> <a href="hosting.html">Hosting</a> </div> </div>
:focus-within keeps it usable from the keyboard: tabbing onto Services opens the list. Phones have no hover, so on touch screens a tap may open it, follow the link, or do nothing depending on the browser. If many visitors are on phones, use the <details> version.
When the dropdown does not show
- ✓The list appears behind other content: give it a z-index (10 or higher) and check that a parent does not have overflow: hidden, which cuts it off.
- ✓The menu closes before the pointer reaches it: there is a gap between the item and the list. Use top: 100% with no margin-top.
- ✓The select looks different on every device: browsers draw <select> with their own control. You can change font, padding and border, but the open list itself stays the system style.
- ✓The form sends the wrong thing: check the value attributes. A missing name on the <select> means it is not sent at all.
Pages made with AI tools
Claude, ChatGPT and Gemini often build navigation dropdowns with JavaScript click handlers. If the menu does nothing once the file is opened somewhere else, ask for “a dropdown using <details> and <summary>, no JavaScript” and the script is no longer a point of failure. The navigation bar around it is covered in how to make a navigation bar in HTML.
Share the page and collect the picks
Open the file in a browser to try every option, then share it. With FileShare Pro you upload the HTML file from the dashboard, copy the link and send it; it opens in any browser and the person opening it needs no account. If the dropdown is part of a form, add data-fsp-form="order" to the <form> tag and each submission, including the picked option, is saved on your file to read or download as CSV, see collect form replies with no backend. Sign up free to share your first page.
Frequently asked
Use <select name="choice"> with an <option value="…">Text</option> for each choice, and close it with </select>. Add a <label> with a matching for and id.
Make the first option <option value="" disabled selected>Choose one</option>. Add required to the <select> so it cannot be submitted empty.
Use <details> with a <summary> for the menu name and the links inside. It opens on click or tap with no script. For hover, show the links with CSS :hover and :focus-within.
Touch screens have no hover, so browsers handle a tap on a hover menu in different ways. Use a click-to-open menu with <details> and <summary> instead.
Drop the file, copy the link — live in seconds, free plan included.
Start sharing free