Most dropdown menu HTML tutorials start with a hover effect. That’s the wrong starting point. A native <select> is often safer than a custom dropdown, and adding role="menu" to a list of navigation links can create more work rather than improve accessibility.
Choose the interaction before the styling. Native selects, disclosure dropdowns and ARIA menus are different controls, even when a designer gives them the same border, chevron and shadow.
Table of Contents
- Choose Native Select, Disclosure or ARIA Menu
- Keyboard Behaviour Every Dropdown Needs
- How to Build a Disclosure Dropdown Step by Step
- Style the Dropdown Panel with CSS
- Accessible Names, Speech Input and Testing
Choose Native Select, Disclosure or ARIA Menu
Start with the lowest-risk pattern
Use a native select when someone needs to choose a value for a form, such as a country or currency. The browser supplies keyboard navigation, typeahead, platform-specific dismissal and screen-reader behaviour. You still need a visible <label>, useful option text and a sensible default, but you don’t need to write keyboard-handling JavaScript.
<form action="/preferences" method="get">
<label for="currency">Currency</label>
<select id="currency" name="currency">
<option value="GBP">Pounds sterling</option>
<option value="EUR">Euros</option>
</select>
<button type="submit">Save currency</button>
</form>
Keep selection separate from submission. Don’t redirect someone merely because they changed an option; let them confirm their choice with an explicit button. The native select guide is a useful starting point when the requirement is data entry rather than navigation.
A disclosure dropdown reveals ordinary links. Its button exposes aria-expanded and references the list through aria-controls; the links retain normal browser behaviour, including opening destinations in another tab.
An ARIA menu button opens an application-style command menu. Its popup has role="menu" and appropriate menu-item descendants, while your code manages focus and the complete menu keyboard model. Use it for commands such as duplicating a document or changing an application setting, not because a navigation panel looks like a menu.
Dropdown patterns and what each one gives you
| Pattern | Markup | Keyboard behaviour | Best use |
|---|---|---|---|
| Native select | select element with option children |
Browser provides arrow keys, typeahead and Escape, according to platform conventions | Single-choice form fields |
| Disclosure menu | button with aria-expanded, aria-controls and a list |
Tab and native button activation work; you add Escape and focus return | Site navigation and grouped links |
| ARIA menu button | button controlling a role="menu" panel with menuitem children |
Full arrow-key model you build and test | Application action menus |
Account for touch and maintenance
Touch behaviour belongs in the initial decision. PublicTechnology reports that 61% of more than one billion GOV.UK visits in 2025 came through mobile browsers. A desktop hover demonstration isn’t a production acceptance test.

A searchable combobox is justified when people need to find options by typing; a shared component library is justified when teams need consistent keyboard and focus behaviour.
For nested application commands, our Menu items support children: hover, ArrowRight, Enter or Space opens the submenu, while ArrowLeft or Esc returns to the parent. Our menu skin renders with the floating skin and should be disabled when embedded inside a popover or dropdown.
Decision rule: A form value means select. Page links mean disclosure. Application commands may justify an ARIA menu.
For custom site navigation, disclosure is the cheapest pattern to get right.
Keyboard Behaviour Every Dropdown Needs
63.6% of tested websites had Keyboard failures in the UK Government’s public-sector accessibility monitoring from 2022 to 2024. That’s a strong reason to treat keyboard operation as functionality, not polish.
The Home Office navigation guidance warns against mouse-dependent dropdowns and navigation triggered merely by tabbing between options. Someone exploring the interface hasn’t necessarily chosen a destination.
Match the keys to the pattern
Disclosure navigation and application menus don’t have identical keyboard requirements. Ordinary disclosure links remain in the Tab sequence while open; an ARIA menu normally uses arrow keys internally, with Tab leaving the widget. Optional arrow-key shortcuts can enhance a disclosure, but they mustn’t replace Tab access.
Expected keyboard behaviour for a dropdown
| Key | Expected behaviour | Failure to avoid |
|---|---|---|
| Tab | Moves to the trigger, then past the closed menu; reaches links in an open disclosure | Focus entering hidden items |
| Enter or Space | Opens from the trigger; activates focused button actions. Enter follows links | Opening only on hover, or overriding native link behaviour |
| ArrowDown | Opens and focuses the first item in a menu, or an arrow-enhanced disclosure | Scrolling the page after your handler has moved focus |
| ArrowUp or ArrowDown | Moves between items when the chosen pattern supports arrow navigation | Focus jumping outside the list |
| Home or End | Moves to the first or last item in a menu; useful as an optional disclosure shortcut | Making long command lists tedious to traverse |
| Escape | Closes the popup and returns focus to the trigger | Focus left on a hidden item |
| Focus outline | Stays visible on the active control | Outline removed with no replacement |
Don’t intercept Space on an ordinary navigation link just to make it resemble a menu item. Links and buttons have different native behaviour, and retaining that distinction makes the interface more predictable.
Make focus movement deliberate
Decide whether arrow movement stops at the ends or wraps around. Either can work for an enhanced disclosure, but the implementation and tests must agree. Home and End provide direct access to the boundaries without repeated key presses.
Never trap focus inside ordinary site navigation. Tab and Shift+Tab must still let someone continue through the page, including when the dropdown is open.
- Keep focus visible. Use a deliberate ring on both the trigger and interactive items. The focus-visible CSS guide covers styling keyboard focus without relying on hover.
- Treat hover as optional. If pointer hover opens a panel, keyboard and touch users still need an explicit activation route.
- Keep order logical. Put the revealed links after their trigger in the DOM rather than repairing an awkward structure with positive
tabindexvalues.
Moving focus is not the same as making a choice. Don’t navigate, submit or execute a command until the user activates it.
How to Build a Disclosure Dropdown Step by Step
<div class="dropdown">
<button
class="dropdown__trigger"
id="menu-trigger"
type="button"
aria-expanded="false"
aria-controls="menu-list"
>
Products
</button>
<ul class="dropdown__panel" id="menu-list" hidden>
<li><a href="/products">All products</a></li>
<li><a href="/integrations">Integrations</a></li>
<li><a href="/pricing">Pricing</a></li>
</ul>
</div>
<noscript>
<p><a href="/products">Browse all products</a></p>
</noscript>
<script>
(() => {
const trigger = document.getElementById("menu-trigger");
const list = document.getElementById("menu-list");
const dropdown = trigger.closest(".dropdown");
const links = [...list.querySelectorAll("a[href]")];
function setOpen(open) {
list.hidden = !open;
trigger.setAttribute("aria-expanded", String(open));
}
function close(returnFocus = false) {
if (returnFocus) trigger.focus();
setOpen(false);
}
trigger.addEventListener("click", () => {
setOpen(list.hidden);
});
dropdown.addEventListener("keydown", (event) => {
if (event.key === "Escape" && !list.hidden) {
event.preventDefault();
event.stopPropagation();
close(true);
return;
}
if (event.target === trigger) {
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
event.preventDefault();
setOpen(true);
const index = event.key === "ArrowDown" ? 0 : links.length - 1;
links[index]?.focus();
}
return;
}
const index = links.indexOf(document.activeElement);
if (list.hidden || index < 0) return;
let next;
if (event.key === "ArrowDown") {
next = Math.min(index + 1, links.length - 1);
} else if (event.key === "ArrowUp") {
next = Math.max(index - 1, 0);
} else if (event.key === "Home") {
next = 0;
} else if (event.key === "End") {
next = links.length - 1;
} else {
return;
}
event.preventDefault();
links[next].focus();
});
dropdown.addEventListener("focusout", (event) => {
if (!dropdown.contains(event.relatedTarget)) close();
});
document.addEventListener("click", (event) => {
if (!dropdown.contains(event.target)) {
close(list.contains(document.activeElement));
}
});
})();
</script>
Build the state changes before the appearance
-
Use a native button.
type="button"prevents accidental form submission, and the browser translates Enter and Space into activation. Don’t add separate handlers for those keys and accidentally toggle the dropdown twice. -
Connect the trigger and list.
aria-controlsmust match the list’s uniqueid, whilearia-expandeddescribes its current state. Generate different IDs for additional dropdown instances. -
Hide the actual content. The
hiddenattribute removes the closed list from normal rendering and keyboard access. Moving the panel off-screen or making it transparent doesn’t achieve the same result. -
Update state together.
setOpen()changes visibility and the announced state through the same function. Scattered class changes and independent ARIA updates are easy to leave out of sync.
The Home Office guidance on understandable interfaces warns against unexpected navigation while people move between options. Opening this disclosure therefore reveals links without selecting a destination.

Handle dismissal without interrupting activation
-
Return focus for Escape. The closure function focuses the trigger before hiding its descendants. Use the keyboard table’s distinction between standard disclosure behaviour and optional arrow shortcuts; this example includes the shortcuts without removing normal Tab access.
-
Check where focus is going.
focusoutbubbles from the links, so inspectrelatedTargetbefore closing. Otherwise, moving from the trigger to a link can hide the very destination someone is trying to activate. -
Dismiss outside the component. The document click listener supports pointer and touch activation without cancelling the outside target’s click. It only restores trigger focus when focus would otherwise remain inside the disappearing panel.
-
Test the integration. Enlarge the page, use a narrow viewport and activate every destination. For client-side routing that keeps the header mounted, also close the disclosure after successful navigation and let the router manage destination focus.
The noscript link provides a basic route when scripting is unavailable. For a stronger navigation fallback, render the full link list visibly on the server and collapse it only after enhancement has initialised.
A working build keeps closed links unreachable, opens from keyboard activation and leaves focus on the trigger after Escape.
Style the Dropdown Panel with CSS
Style the panel after its behaviour works. Dropdown menu HTML doesn’t need a framework-specific positioning system for a simple panel, but it does need a clear containing block and enough room for its content.
Position the panel without clipping it
Give the wrapper position: relative and the panel position: absolute. Align the panel to an edge that leaves room in the actual header, rather than assuming every trigger sits near the left side of the viewport.
A large z-index won’t escape an ancestor’s clipping or stacking context. If a header uses overflow: hidden, fix that layout constraint or use a positioning solution that renders the panel outside the clipped container.
- Preserve hiding. A scoped
[hidden]rule prevents a laterdisplaydeclaration from accidentally revealing the panel. - Constrain long lists. Use a viewport-aware maximum height and vertical scrolling, then check that keyboard-focused links scroll into view.
- Allow labels to wrap. Translated text and enlarged fonts need room. Don’t force every destination onto an unbroken line.
Keep decoration separate from interaction
Use :focus-visible for a clear keyboard indicator, and keep hover styling as an additional visual cue. Give links generous padding so touch users don’t need to target the text precisely.
A dropdown shadow can improve separation, but it can’t fix a clipped panel, an invisible focus ring or an undersized tap target.
This CSS uses the classes from the markup. On narrow viewports it puts the list back into document flow, avoiding an overlay that extends beyond the page edge.
.dropdown {
position: relative;
display: inline-block;
max-inline-size: 100%;
}
.dropdown [hidden] {
display: none !important;
}
.dropdown__trigger,
.dropdown__panel a {
padding: 0.75rem 1rem;
font: inherit;
}
.dropdown__panel {
position: absolute;
inset-block-start: 100%;
inset-inline-start: 0;
z-index: 10;
box-sizing: border-box;
inline-size: max-content;
min-inline-size: 100%;
max-inline-size: calc(100vw - 2rem);
max-block-size: 60dvh;
overflow-y: auto;
margin: 0.25rem 0 0;
padding: 0.25rem;
list-style: none;
background: #fff;
color: #111;
border: 1px solid #777;
box-shadow: 0 0.5rem 1.5rem rgb(0 0 0 / 15%);
}
.dropdown__panel a {
display: block;
color: inherit;
overflow-wrap: anywhere;
}
.dropdown__trigger:focus-visible,
.dropdown__panel a:focus-visible {
outline: 2px solid #005fcc;
outline-offset: 2px;
}
.dropdown__panel a:hover {
background: #eee;
}
@media (max-width: 40rem) {
.dropdown__panel {
position: static;
inline-size: 100%;
max-inline-size: 100%;
}
}
@media (prefers-reduced-motion: no-preference) {
.dropdown__panel a {
transition: background-color 120ms ease;
}
}
The example doesn’t animate opening or closing. If you add that decoration, honour reduced-motion preferences and never delay keyboard focus until a transition finishes.
Accessible Names, Speech Input and Testing
Why can a keyboard-accessible dropdown still be hard to operate by voice? Speech-recognition users say the words they can see, but developers sometimes give the same control a different programmatic name.
The Health Research Authority’s accessibility statement identifies dropdowns whose accessible labels didn’t match their visible labels, creating difficulty for speech-recognition users and failing WCAG 2.2 Success Criterion 2.5.3. A working key handler doesn’t compensate for that mismatch.

Inspect what the control actually announces
For the example button, the visible text Products already supplies its accessible name. Adding aria-label="Open navigation options" would replace that useful name with words the user can’t see.
Inspect the computed accessibility tree in Chrome DevTools or Firefox Accessibility Inspector. Check the actual name, role and expanded state rather than assuming the presence of ARIA attributes proves the control works.
- Match visible words. Keep Products in the accessible name if Products is the visible label. Decorative chevrons shouldn’t add unnecessary spoken content.
- Expose the state. Confirm that the browser reports the trigger as expanded or collapsed after activation, not just that its colour changes.
- Use honest item semantics. Destinations should be links with real
hrefvalues; local operations should be buttons or correctly implemented menu actions. - Announce meaningful outcomes. A preference save, validation error or failed command needs perceivable feedback. Associate field errors with their controls and use an appropriate status region for asynchronous results.
Avoid making the entire dropdown an aria-live region. Ordinary focus and expanded-state announcements already describe navigation; announcing the whole panel repeatedly adds noise.
Run a reproducible interaction test
The GOV.UK basic accessibility checking guide recommends manual keyboard checks alongside automated testing. Use a repeatable sequence rather than opening the panel once and declaring it accessible.
- Start without the mouse. Tab to Products and verify that you can locate focus against the actual header background.
- Activate the trigger. Test Enter and Space independently, confirming that neither produces an immediate open-and-close cycle.
- Traverse the contents. Tab through disclosure links; test arrow movement where implemented. With a screen reader, confirm that the focused destination or command has an understandable name.
- Dismiss from within. Press Escape on a descendant and verify that Products becomes the active element.
- Continue the journey. Tab again and check that the closed contents are skipped. Repeat backwards with Shift+Tab and then test dismissal by clicking elsewhere.
Run the same journey with NVDA and Firefox or Chrome, then VoiceOver and Safari where those platforms are supported. The screen-reader testing guide can help turn those checks into a consistent team routine.
Speech input needs its own pass: speak the visible trigger label and then a visible destination. Also test touch on a phone, substantial browser zoom, reduced-motion settings and long translated labels. Automated checks won’t tell you whether the panel is awkward to reach with a thumb.
Test inside the real application
An isolated component demo misses sticky headers, route transitions and account-specific menu items. Check signed-in states, permission-dependent actions and repeated dropdown instances, including whether IDs remain unique.
For menus behind a login, CheckMyApp’s guide to testing authenticated journeys with coding agents provides useful context for exercising the surrounding workflow. Browser automation can verify state and focus assertions, but a person still needs to assess spoken output and speech-input operation.
Dropdown symptoms, causes and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| Tab reaches hidden links | List only visually hidden | Use the hidden attribute on the list |
| Menu opens only on hover | Hover-only JavaScript | Add click activation; native buttons supply Enter and Space |
| Focus lost after Escape | Trigger not stored or refocused | Store the trigger and focus it on Escape closure |
| Screen reader gives no state | aria-expanded not toggled |
Update aria-expanded with the list state |
| Click on an item closes menu first | focusout fires before click |
Check relatedTarget before closing |
| Keyboard focus passes through closed menu | Items still in tab order | Remove closed items from keyboard access, preferably by hiding the list |
A failing test on any row blocks release. Fix the behaviour before adjusting the chevron, animation or shadow.
DOM Studio offers headless web component primitives and Vue components with keyboard handling, ARIA semantics and focus management built in. Visit DOM Studio to choose a dropdown or menu foundation, then test it within your navigation, routes and application states.
