Dropdown Menu
Hover dropdown menu with icons and dividers.
<div class="relative group inline-block">
<button class="px-5 py-2.5 rounded-xl bg-white border border-slate-200 text-sm font-bold text-slate-700 hover:border-slate-300 flex items-center gap-2">
Options
<svg class="w-4 h-4 text-slate-400 group-hover:rotate-180 transition-transform" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7"/></svg>
</button>
<div class="absolute top-full left-0 mt-2 w-56 rounded-2xl border border-slate-200 bg-white shadow-xl p-2 opacity-0 invisible group-hover:opacity-100 group-hover:visible transition-all">
<a href="#" class="flex items-center gap-3 px-3 py-2.5 rounded-xl text-sm font-medium text-slate-700 hover:bg-slate-100 transition-colors">
<span class="w-8 h-8 rounded-lg bg-indigo-100 text-indigo-600 flex items-center justify-center text-sm">📝</span>
Edit profile
</a>
<a href="#" class="flex items-center gap-3 px-3 py-2.5 rounded-xl text-sm font-medium text-slate-700 hover:bg-slate-100 transition-colors">
<span class="w-8 h-8 rounded-lg bg-emerald-100 text-emerald-600 flex items-center justify-center text-sm">⚙️</span>
Settings
</a>
<div class="h-px bg-slate-100 my-2"></div>
<a href="#" class="flex items-center gap-3 px-3 py-2.5 rounded-xl text-sm font-medium text-red-600 hover:bg-red-50 transition-colors">
<span class="w-8 h-8 rounded-lg bg-red-100 text-red-600 flex items-center justify-center text-sm">🚪</span>
Sign out
</a>
</div>
</div>Free to use in personal and commercial projects. No attribution required.
About this dropdown menu
Dropdown menus pack navigation into a compact trigger. This tailwind dropdown menu opens on hover with a smooth fade, showing icon+label rows and a divider before the destructive action. It is the standard pattern for user account menus, settings, and overflow actions.
The hover approach (group-hover) works for demos and simple sites, but production menus should open on click for touch and keyboard support. The structure stays the same; only the trigger changes from hover to a click handler toggling visibility.
Keep dropdown items scannable: icon, short label, optional shortcut hint on the right. Group related items and separate destructive actions with a divider. Seven items is the practical max before the menu feels overwhelming.
Toolbars and navbars accumulate more actions than fit comfortably in a row. A dropdown compresses a list of related actions behind one labeled button and reveals them on demand. It is the standard shape for account menus, sort controls, and overflow actions: one trigger, a short fan of choices, then it collapses away.
The wrapper is relative group inline-block. The menu is absolute top-full left-0 mt-2 w-56 rounded-2xl border bg-white shadow-xl p-2, hidden with opacity-0 invisible and revealed via group-hover:opacity-100 group-hover:visible plus transition-all for the fade. Items are flex rows pairing w-8 h-8 rounded-lg icon tiles with short labels; the trigger's chevron rotates with group-hover:rotate-180 to signal the open state.
For production, replace hover with a click toggle that also closes on outside click and Escape. Align with right-0 when the trigger sits near the viewport edge. Keep five to seven items; beyond that the menu needs its own search filter. Cluster related actions together and set destructive ones apart with a divider rule.
The classic hover-menu bug is the gap: mt-2 leaves dead space between the button and the menu, so the menu closes while the mouse travels down to it. Users call the menu broken when it's just geometry. Fix it with padding instead of margin for the gap, or add a short close delay so brief pointer slips don't collapse the menu.
Design notes
When to use
A dropdown menu suits a single button that fans out into a short list of related actions, like an Options button with profile, settings, and logout. The icons beside each item speed up scanning, and the divider groups separate destructive actions from safe ones. The chevron that rotates on open is a small but effective cue that the menu is expanded.
What to avoid
Do not build a dropdown with more than about eight items, at that point a listbox or a dedicated page filters better. Avoid hover-only activation for anything important, because the menu vanishes the moment the pointer slips, which frustrates users on trackpads. Nesting submenus inside submenus is another trap that turns a simple control into a maze.
Accessibility
A hover-only dropdown locks out keyboard users, so open it on focus and Enter as well, and let Escape close it. Use aria-expanded on the button and menu roles on the list so assistive tech announces the open state.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Dark
The dark menu fits dark headers and admin navigation.
Right aligned
Right-align the menu when the trigger sits at the right edge of a header.
With user header
Add the user header for account menus that show who is signed in.
Where to use it
- ✓ User account menus
- ✓ Settings dropdowns
- ✓ Navigation overflow
- ✓ Action menus on cards
Frequently asked questions
Hover vs click for dropdown menus?
Hover is fine for demos but click is better for production: it works on touch devices and is more accessible. Use JavaScript to toggle on click.
How do I close a dropdown when clicking outside?
Add a document click listener that closes the menu when the click target is outside the dropdown container.
How many items should a dropdown have?
Five to seven. More than that suggests the items deserve their own page or a mega-menu instead.
How do I add keyboard navigation to a dropdown menu?
Move focus into the menu on open, let ArrowUp and ArrowDown cycle through items, and close on Escape returning focus to the trigger. Use roving tabindex or simply make each item a real link or button so Tab works naturally. Set aria-expanded on the trigger to reflect the open state.
How do I animate a dropdown menu opening?
Animate opacity from 0 to 1 with a small translateY slide of 4 to 8px over about 150ms. For height animation without knowing the content size, use the grid-template-rows 0fr to 1fr transition trick. Avoid animating to auto height, which cannot transition.
Should dropdown menus open on hover for desktop?
Hover with a small intent delay works on desktop, but always pair it with :focus-within so keyboard users get the same menu. On touch devices hover does not exist, so the trigger must also toggle on click or tap. Test the menu with a keyboard only, no mouse, before shipping.
Customization tips
For click-to-open, replace group-hover with a JavaScript toggle. Add keyboard navigation with arrow keys for full accessibility. Align right with right-0 instead of left-0 when near the viewport edge.
Related elements
Delete item?
This action cannot be undone. The item will be permanently removed.
Modal Dialog
Centered modal with backdrop blur and close button.
CSS Tooltip
Pure CSS tooltip on hover, no JavaScript.
Command Palette
Cmd+K command palette with search and shortcuts.