Skip to content
IndexRequest a UIAboutContact

Hover Mega Menu

A header whose items open a two-column panel on hover, focus or tap, with Escape to close.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a header navigation bar with three items: Products, Resources and Company. Each item is a button with aria-expanded and aria-controls that opens a 300 pixel wide panel directly beneath it containing two columns of links with small uppercase headings (for example Build, Ship for Products). Open on mouse hover with a 150 millisecond close delay, and also on focus, Enter, Space and tap; Escape closes and returns focus to the trigger; Arrow Down moves into the panel. Only one panel is open at a time. Light minimal style, white panel, 12 pixel radius, soft shadow, 160 millisecond fade-drop with a prefers-reduced-motion fallback. Plain HTML, CSS and JavaScript.

About this pattern

Definition

A mega menu is a large dropdown panel under a navigation item that groups many links into labelled columns, so people can scan a whole section at once.

Purpose & UX principles

  • Best for sites with many sections; group links under short headings and keep each panel to about six links.
  • Open on hover with a small delay, but also on focus, Enter and tap so keyboard and touch users are not excluded.
  • Close on Escape, on moving away, or when another item opens; keep a gap-free hover path between trigger and panel.

Interaction states

  • Closed, open (one panel at a time), keyboard focus on trigger, focus inside the panel.

Motion specification

  • Panel fades and drops 6px over 160ms; closing is delayed 150ms to forgive small pointer slips.
  • Reduced motion: instant show and hide.

Responsive behaviour

  • Under about 800px replace it with a hamburger and an accordion list.
  • Do not open on hover on touch devices; use tap to toggle.

Code

HTML
<div class="bx"><nav class="nv" id="nv" aria-label="Main"><button data-i="0" aria-expanded="false">Products</button><button data-i="1" aria-expanded="false">Resources</button><button data-i="2" aria-expanded="false">Company</button><div class="pn" id="pn" hidden></div></nav><p class="out" id="out" aria-live="polite">Hover, focus or tap an item.</p></div>

Related patterns

Top Navigation

↗
Top NavigationNavigation

Dropdown Menu

↗
Dropdown MenuOverlays & Dialogs

Tab Navigation

↗
Tab NavigationNavigation