CSS Mega Menu
A wide multi-column dropdown panel under a nav item, opened on hover or keyboard focus.
HTML
<nav class="mega-menu" aria-label="Main">
<div class="mega-menu-item">
<button class="mega-menu-trigger" type="button">Products</button>
<div class="mega-menu-panel">
<div>
<p class="mega-menu-heading">Build</p>
<a href="#">Site builder</a>
<a href="#">Forms</a>
<a href="#">Checkout</a>
</div>
<div>
<p class="mega-menu-heading">Grow</p>
<a href="#">Email</a>
<a href="#">Analytics</a>
<a href="#">SEO tools</a>
</div>
<a class="mega-menu-promo" href="#">New: AI site audit</a>
</div>
</div>
<a href="#">Pricing</a>
<a href="#">Docs</a>
</nav>
CSS
.mega-menu {
display: flex;
align-items: center;
gap: 4px;
font: 500 14px system-ui, sans-serif;
}
.mega-menu-item {
position: relative;
}
.mega-menu > a,
.mega-menu-trigger {
display: block;
padding: 9px 12px;
border: 0;
border-radius: 8px;
background: none;
color: #334155;
font: inherit;
text-decoration: none;
cursor: pointer;
}
.mega-menu > a:hover,
.mega-menu-trigger:hover,
.mega-menu-item:focus-within .mega-menu-trigger {
background: #e2e8f0;
color: #0f172a;
}
.mega-menu-panel {
position: absolute;
top: 100%;
left: 0;
z-index: 10;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px 16px;
width: min(360px, calc(100vw - 32px));
margin-top: 8px;
padding: 16px;
border-radius: 14px;
background: #ffffff;
box-shadow: 0 0 0 1px #0f172a14, 0 18px 40px -12px #0f172a40;
opacity: 0;
visibility: hidden;
transform: translateY(-6px);
transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}
/* Invisible bridge across the gap so hover is not lost */
.mega-menu-panel::before {
content: "";
position: absolute;
top: -10px;
right: 0;
left: 0;
height: 10px;
}
.mega-menu-item:hover .mega-menu-panel,
.mega-menu-item:focus-within .mega-menu-panel {
opacity: 1;
visibility: visible;
transform: none;
}
.mega-menu-heading {
margin: 0 8px 6px;
color: #64748b;
font-size: 11px;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.mega-menu-panel a {
display: block;
padding: 7px 8px;
border-radius: 8px;
color: #0f172a;
text-decoration: none;
}
.mega-menu-panel a:hover {
background: #f1f5f9;
}
.mega-menu-panel .mega-menu-promo {
grid-column: 1 / -1;
margin-top: 8px;
padding: 10px 12px;
background: #eef2ff;
color: #4338ca;
font-weight: 600;
}
.mega-menu a:focus-visible,
.mega-menu-trigger:focus-visible {
outline: 2px solid #4f46e5;
outline-offset: 1px;
}
@media (prefers-reduced-motion: reduce) {
.mega-menu-panel { transition: none; }
}
About this CSS Mega Menu
This CSS Mega Menu is 107 lines of pure CSS (2.0 KB) with no JavaScript and no dependencies. It uses transitions, transforms, box shadows and CSS Grid. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#334155#e2e8f0#0f172a#ffffff#0f172a14#0f172a40#64748b#f1f5f9#eef2ff#4338ca
How to use this mega menu
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.mega-menuclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.