Skip to content
IndexRequest a UIAboutContact

Dropdown Menu

An action menu with full keyboard support, typeahead and outside-click closing.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a menu button "Options" with a dropdown menu of five items: Rename, Duplicate, Move to folder (disabled), Share and Delete (danger). The trigger has aria-haspopup="menu", aria-expanded and aria-controls; the menu is role="menu" with role="menuitem" children. Open with click, Enter, Space or ArrowDown (focus the first enabled item); ArrowUp and ArrowDown move focus skipping disabled items; Home and End jump; typing a letter focuses the next item starting with it; Escape closes and returns focus to the trigger; Tab closes; clicking outside closes. Selecting an item shows "Chose: <name>" below and closes the menu. The menu opens below with an 8px gap, flips above if it would overflow the demo container, and animates scale 0.96 to 1 plus fade over 140ms. Use a roving tabindex on the items. Reduced motion: opacity only.

About this pattern

Definition

A button that opens a list of actions below it. Choosing an item runs the action and closes the menu. It follows the WAI-ARIA menu button pattern.

Purpose & UX principles

  • Groups secondary actions behind one control to keep the interface calm.
  • Use a native select for choosing a value in a form; this pattern is for actions ("Rename", "Duplicate", "Delete").
  • Put destructive actions last and visually distinct.

Interaction states

  • Closed, open, item hover and active (keyboard-highlighted), disabled item.
  • Trigger: aria-haspopup="menu", aria-expanded, aria-controls.
  • Keys: Enter, Space or Down opens; Up and Down move; Home and End jump; typing a letter jumps to a matching item; Escape closes and returns focus to the trigger; Tab closes.

Motion specification

  • Menu: scale from 0.96 (origin top-left) and fade, 140ms ease-out.
  • Highlight moves instantly; no transition, so keyboard navigation feels immediate.
  • Reduced motion: opacity only.

Responsive behaviour

  • The menu opens below the trigger and flips upward if there is not enough room.
  • On phones consider an action sheet that slides up from the bottom, with the same items.

Code

HTML
<div class="area" id="area">
  <div class="wrap">
    <button class="trig" id="trig" aria-haspopup="menu" aria-expanded="false" aria-controls="menu">Options ▾</button>
    <ul class="menu" id="menu" role="menu" aria-label="Options" hidden>
      <li role="menuitem" tabindex="-1">Rename</li><li role="menuitem" tabindex="-1">Duplicate</li>
      <li role="menuitem" tabindex="-1" aria-disabled="true">Move to folder</li><li role="menuitem" tabindex="-1">Share</li>
      <li role="separator"></li><li role="menuitem" tabindex="-1" class="danger">Delete</li>
    </ul>
  </div>
  <p id="out" role="status">Choose an option</p>
</div>

Related patterns

Tooltip

↗
TooltipFeedback & Notifications

Modal Dialog

↗
Modal DialogOverlays & Dialogs

Search Input

↗
Search InputInputs & Forms