Skip to the content

Mega menu

A site header whose top-level items open a wide panel.

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

    Give each panel a width in its own class, and a margin-top for the gap under the bar: the engine only decides where a panel goes. Keep the entries of the row unpositioned, with no transform, give the header side paddings, which are the margins a panel never crosses, an opaque background and a z-index above the page.
  3. Add custom JS

  4. Tune it

    Custom attributes
    Select the section on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-mega-menu Goes on the header and takes no value: leave the value field empty. It marks the block the engine mounts on, which carries the settings, the mode and the state, and against which every panel and the surface are placed. Without it on any element of the page, the embed marks the header around the first item itself.
    data-mega-menu-item Marks one entry of the row, the block holding a trigger and, when it has one, its panel. An entry without a panel is a plain link of the row. Without it on any block the menu is not mounted, and the console says so. [ Required ]
    data-mega-menu-trigger Marks what opens the panel of its entry, a link to the section's own page. With the script it becomes a button, with aria-expanded and aria-controls. Without it the first link or button of the entry is taken. [ Optional ]
    data-mega-menu-panel Marks the panel of an entry, placed right after its trigger. Its width is its own class. An entry without it is a plain link; a menu where no entry has one is not mounted. [ Required ]
    data-mega-menu-content Marks the one block inside a panel that holds everything it shows: it is what crosses sideways when the panel changes item, and what folds on a phone. Without it the first block of the panel is taken. [ Optional ]
    data-mega-menu-link Marks what arrives one after the other inside a panel, the links as a rule. It also draws the accent line under the pointer. Without it on anything in a panel, every link of that panel is taken. [ Optional ]
    data-mega-menu-feature Marks the frame of a featured picture, a box holding an image: the frame is uncovered from the side the panel arrives from while the picture settles to its size. Without it nothing is uncovered. [ Optional ]
    data-mega-menu-list Marks the row of entries, which becomes the sheet on a phone. Without it the parent of the first entry is taken. [ Optional ]
    data-mega-menu-toggle Marks the button that opens and closes the sheet on a phone, hidden on a wide window. Without it nothing opens the phone menu but JavaScript. [ Optional ]
    data-mega-menu-surface Marks the one box behind every panel, the one that morphs: its colour, radius and shadow are its class. It sits in the header, after the row. Without it the engine builds one, cream with a 14px radius. [ Optional ]
    data-mega-menu-mode, data-mega-menu-state Written by the engine on the header: the mode, desktop or phone, and the state, closed, opening, open or closing. The stylesheet lays the menu out from them. Never written by hand. [ Optional ]
    data-mega-menu-active, data-mega-menu-leaving Written by the engine on an entry: active on the one whose panel shows, or whose accordion is open, leaving on the one it replaces while its content goes. Never written by hand. [ Optional ]
    Settings
    Every setting is a custom attribute too, added the same way and on the same section. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-mega-menu-accent #ffab1a Colour of the line drawn under a link of a panel while the pointer or the keyboard is on it, written on the menu as --mega-menu-accent. Options: any CSS colour; set it empty and a --mega-menu-accent of the stylesheet takes over.
    data-mega-menu-open 0.6 Time the panel takes to unfold from the bar when nothing was open, in seconds; the links and the picture are timed from it.
    data-mega-menu-close 0.35 Time the panel takes to fold back up, in seconds.
    data-mega-menu-morph 0.55 Time the surface takes to travel from one item's panel to another's, in seconds; the cross of the content, the links and the picture are timed from it, and so are the accordions of the phone menu.
    data-mega-menu-open-ease power4.out Shape of the unfolding, a GSAP ease name. Options: any GSAP ease; an out ease answers at once and settles, inOut starts late under a pointer.
    data-mega-menu-morph-ease power3.inOut Shape of the morph, a GSAP ease name; the phone sheet drops on the same one. Options: any GSAP ease; inOut reads as one box that travels, an out ease as a box that snaps then drifts.
    data-mega-menu-slide clamp(20px, 2.6vw, 44px) How far the content travels sideways when the panel changes item, any CSS length: the old content leaves that far towards the side the pointer came from, the new one comes in from the other.
    data-mega-menu-rise clamp(8px, 1.3vh, 14px) Height a link comes up from as it arrives, any CSS length; the rows of the phone sheet rise from twice that.
    data-mega-menu-stagger 0.035 Delay between two links arriving, in seconds.
    data-mega-menu-hover true Whether a pointer resting on an item opens its panel. Touch never does: a tap is a click. Options: true; false, and the panels open on a click or from the keyboard only.
    data-mega-menu-hover-delay 0.09 How long the pointer has to rest on an item before its panel opens, in seconds. An item crossed on the way down to the open panel waits longer on its own.
    data-mega-menu-close-delay 0.22 How long the pointer may stay off the menu before it closes, in seconds; it is what carries the pointer across the gap between the bar and the panel.
    data-mega-menu-breakpoint 767 Widest window, in px, that gets the phone menu: the button, the sheet and the accordions. The look of the preview changes at the same width, 767, in the stylesheet.
    data-mega-menu-escape true Whether Escape closes the menu and hands the focus back to the item. Options: true; false.
    data-mega-menu-close-on-outside true Whether a click outside the menu closes it. Options: true; false.
    data-mega-menu-close-on-link true Whether a click on a link of a panel closes the menu, for a link that stays on the page. Options: true; false.
    data-mega-menu-label-open Menu Text of the phone button while the menu is closed. Not written when the button holds an element, an icon for one. Options: any text.
    data-mega-menu-label-close Close Text of the phone button while the menu is open. Options: any text.

What it does

Mega menu is an animated navigation component for Webflow and vanilla JavaScript, built on GSAP 3. Also called morphing mega menu, mega dropdown navigation or morphing dropdown menu.

A site header whose top-level items open a wide panel. The panel is one single surface: it unfolds under the item, then morphs, size and place, from one item to the next instead of closing and opening again. What it holds crosses with a short slide in the direction of the move, the links come up one after the other and the featured picture is uncovered from the side the panel arrives from. It opens under a pointer that rests on an item, with intent: a pointer that crosses another item on its way down to the panel does not switch it. A click or a tap opens it too and pins it. The whole menu works from the keyboard: Tab walks the items and the open panel in order, the arrow keys move along the row and through a panel, Escape closes and hands the focus back to the item. The triggers carry aria-expanded and aria-controls, nothing traps the focus, and a click outside closes. Under the phone breakpoint the row becomes a sheet under the bar that fills the window, and the same panels fold as accordions. Under reduced motion every state is reached at once. Without the script the items are plain links to their own pages, and a panel still shows under the pointer or the keyboard. Not the curtain menu, which covers the page, and not the anchored menu, which is one box that unfolds: here the page stays, and it is the panel that travels along the header. Pattern type mega menu, mega dropdown, morphing navigation.

Updated

Questions

Put data-mega-menu on the header, data-mega-menu-item on each entry of its row, and inside an entry its trigger, data-mega-menu-trigger, then its panel, data-mega-menu-panel, with one block marked data-mega-menu-content around what it shows. Give each panel a width in its own class: the engine only decides where it goes. One surface behind every panel travels and changes size from item to item, so the menu never closes and opens again.

GSAP 3 drives the motion, with no plugin, and the engine reads it at each interaction, so the tags can come in any order and Webflow's own copy is used when it is there. Without GSAP the menu still opens, switches panel and closes, at once and with no motion.

Yes. Tab reaches each item, Enter or Space opens and closes its panel, Left and Right move along the row and carry the open panel with them, Down enters the panel and Escape closes it and puts the focus back on the item. The triggers carry aria-expanded and aria-controls, written by the engine, and the focus is never held.

It already waits. A panel opens after the pointer has rested on an item for data-mega-menu-hover-delay, 0.09 s by default, and an item crossed on the way down to the open panel waits longer on its own. data-mega-menu-close-delay, 0.22 s by default, is how long the pointer may stay off the menu, which carries it across the gap between the bar and the panel.

At or under data-mega-menu-breakpoint, 767 px by default, the row becomes a sheet under the bar that fills the rest of the window, opened by the button marked data-mega-menu-toggle. The same panels fold under their triggers as accordions, one open at a time, and the page behind is held while the sheet is open.