A responsive mega menu built with Tailwind CSS and vanilla JavaScript for a travel brand: each top-level item opens a full-width panel with grouped link lists on the left and featured image cards on the right. It suits travel, e-commerce and publishing sites that promote highlighted content inside the main navigation.
How it works
The root is .mmf-root, which contains the header and some sample page content. Inside the header, nav#mmf-nav (.mmf-nav) holds a list with two .mmf-trigger buttons, two plain links and a call-to-action. Each trigger points with aria-controls to its .mmf-panel. A panel is a 12-column grid: the left seven columns hold link groups with .mmf-link items, the right five hold .mmf-card links with a photo, a dark gradient overlay and a title with price.
From the lg breakpoint the panel is positioned with lg:absolute lg:inset-x-0 lg:top-full, so it spans the whole header and drops below it with the mmf-drop animation. Below lg the nav is hidden behind the .mmf-burger button and the panels become stacked accordions inside it.
The script initializes every .mmf-root on DOMContentLoaded. A click on a trigger flips aria-expanded and the panel's hidden attribute; on desktop it closes other panels first. Escape closes the open panel (or the mobile menu) and returns focus. Clicking or tabbing outside the header closes desktop panels. The Destinations panel starts open as a desktop preview; on phones the script collapses it on load.
Customization
aria-expanded="true"on the first.mmf-triggerand the missinghiddenon#mmf-panel-destinations: setaria-expanded="false"and addhiddenso every panel starts closed.lg:col-span-7andlg:col-span-5inside a panel: change the split between link lists and featured cards, for example8and4with a single card.lg:aspect-[3/4]on the card images: uselg:aspect-squarefor shorter cards and a lower panel.bg-emerald-700,text-emerald-700and#047857instyle.css(.mmf-link:hover,.mmf-trigger[aria-expanded="true"]): swap for your brand color.bg-[#fbf8f2]on the header and.mmf-nav: change the bar background; keep both values equal so the mobile menu matches.- The
New routebadge (bg-amber-300) inside a.mmf-card: copy it to other cards or remove it. min-width: 64remin bothstyle.cssandscript.js: change both together if you move the desktop breakpoint fromlgtoxl.
Use cases
- Ecommerce stores: grouped link columns and featured photo cards guide shoppers to key categories
- Large corporate sites: many pages fit into one organized dropdown panel
- Content publishers: featured cards promote articles or collections inside the menu
- Mobile navigation: the menu turns into an accordion on small screens with keyboard support
Accessibility
Triggers are real buttons with aria-expanded and aria-controls, the nav has aria-label="Main", and the burger button has a screen-reader label plus aria-expanded. Panels are closed with the hidden attribute, so collapsed links are out of the Tab order. Escape closes menus and restores focus. Every image has a descriptive alt, width, height and decoding="async", and cards in the closed panel use loading="lazy". Links and buttons have visible emerald focus outlines, decorative icons and overlays are aria-hidden, and animations stop under prefers-reduced-motion: reduce.
Usage notes
The photos come from Unsplash; replace them with your own images. The demo links use href="#" and the script prevents navigation for them; real URLs work normally. Several menus on one page work, as long as each panel id is unique.