Home / Website Sections / Mega Menu Navigation

Mega Menu Navigation in JavaScript, Free with Live Demo

Free mega menu in plain JavaScript. Multi-column dropdowns, keyboard arrows and Escape, hover intent, and a slide-in mobile drawer. One HTML file, no library.

Open live demoDownload HTML fileView code on GitHub
Mega Menu Navigation JavaScript project: a big dropdown menu with columns, keyboard support and a mobile drawer

Runs on: DOM events. Works in all modern browsers.

What is the Mega Menu Navigation?

A full mega menu for a shop or content site. Each top item opens a wide panel with columns of links and a promo card with a photo.

It works with a mouse, a keyboard and on phones, where the menu turns into a slide-in drawer with folding sections.

Good for

  • Online shops with many categories
  • News and magazine sites
  • Company sites with lots of pages
  • Any header that has outgrown a simple list

What this project does

How it works

  1. Buttons, not linksEach top item is a button with aria-expanded, so screen readers announce open and closed.
  2. Hover with a delayA short timer stops menus flickering open when the mouse just passes over.
  3. One key mapArrow keys move between items, Down opens a panel and Escape closes it and returns focus.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

btn.addEventListener("keydown", (e) => {
  if (e.key === "ArrowDown") { open(btn); panel.querySelector("a").focus(); }
  if (e.key === "Escape") { close(); btn.focus(); }
});
item.addEventListener("pointerenter", () => {
  clearTimeout(timer);
  timer = setTimeout(() => open(btn), 120); // hover intent
});

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

Should menu items be links or buttons?

If the item opens a panel, use a button. Links should go to a page.

How do I stop the menu closing too fast?

Add a short delay on pointer leave, around 250 ms, and cancel it when the pointer enters the panel.

Is hover enough?

No. Touch and keyboard users need click and key support too, which this project includes.

More Website Sections projects