Build a Responsive Navigation Bar With Mega Menu and Mobile Drawer in HTML

A complete single-file site header with a hover, click and arrow-key mega menu on desktop and an animated hamburger drawer with accordions on small screens.

You getone complete HTML file in a single code block, then 3 short ideas to extend it.

The prompt

Prompt
Act as a senior front-end designer who writes clean, accessible vanilla HTML, CSS and JavaScript.

Build a responsive site header for Harbor & Pine, a member-owned outdoor co-op: a desktop mega menu, a mobile slide-in drawer, and a short hero section below it.

Gear, Trips and Learn open mega panels with three titled columns of links (name plus one-line description) and a dark feature card. Journal and Stores are plain links. Sign in and a Join the co-op button sit on the right.

Rules:
1. From 900px up, panels open on hover with short delays, toggle on click, and close on outside click, Escape or tabbing away. Keep aria-expanded in sync.
2. Keyboard: Left/Right move between top items, Down opens a panel and focuses its first link, Up/Down step through links, Left/Right jump between columns, Escape closes and returns focus.
3. Below 900px, a hamburger that morphs into an X opens a drawer under the header with accordion sections, a dim backdrop, trapped focus, Escape to close, and auto-close on resize to desktop.
4. Cream background, forest green, amber focus rings, system fonts, 44px touch targets. It must look right from 360 to 1280px.
5. Honor prefers-reduced-motion. Use no external files, storage or forms. Links show the chosen item in a status line instead of navigating.

Output format: one complete HTML file in a single code block, then 3 short ideas to extend it.

Example output

One HTML file. Save it and open it in any browser.Open full screen

Example: Harbor & Pine, a co-op header with a mega menu and a mobile drawer.

  • Hover or click Gear, Trips or Learn to open a three-column panel with a feature card.
  • Keyboard: Tab to the menu and use ← → to move between items. Press ↓ to enter a panel, then ← → to jump columns. Esc closes the panel.
  • Mobile: narrow the window below 900px. The hamburger morphs into an X and opens a drawer with accordion sections.
  • Any link you pick appears in the status box.
Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • One 900px breakpoint with separate desktop and drawer markup keeps both layouts simple and predictable at every width.
  • Spelling out each key (arrows, Home, End, Esc) and syncing aria-expanded makes the keyboard behaviour work on the first try.
  • Opening on hover with short delays, plus click-to-pin, stops panels from flickering when the mouse crosses gaps.

Paste into ChatGPT, Claude or Gemini. Save the code as an .html file and open it in a browser, or use the chat's preview/canvas. Resize the window to test both the desktop and drawer layouts.

Common edits

  • Swap the brand, menu labels and link data in the NAV array to match your own site's sections.
  • Change the breakpoint from 900px or the palette variables to fit a different layout or brand.

Prompt details

By
Prompts-GPT editors
Published
How prompts are written and checked

Did this prompt work?

Keep exploring

More in Design