Mega menus are perfect for websites with a lot of navigation items or categories. Rather than stacking a long list of links in a single column, mega menus break them into organized sections, often displayed in multiple columns. They’re commonly used on e-commerce sites, news portals, and dashboards.
In this tutorial, you’ll learn how to create a simple, responsive mega menu using Bootstrap 5 — no custom JavaScript required!
What You Need
To follow along, you’ll need:
- Basic understanding of HTML and Bootstrap
- Bootstrap 5 included in your project
You can use the CDN like this:
1 2 3 4 5 6 7 8 | <!-- Bootstrap CSS --> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" /> <!-- Bootstrap JS + Popper.js --> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"></script> |
Building the Navbar with Mega Menu
Let’s dive into the code. Below is a complete working example of a mega menu inside a Bootstrap navbar.

✅ Full HTML Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | <!doctype html> <html lang="en"> <head> <title>Mega Menu Example</title> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" /> </head> <body> <header> <nav class="navbar navbar-expand-lg bg-body-tertiary"> <div class="container position-relative"> <a class="navbar-brand" href="#">Navbar</a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNavDropdown"> <ul class="navbar-nav"> <li class="nav-item"><a class="nav-link active" href="#">Home</a></li> <li class="nav-item"><a class="nav-link" href="#">Features</a></li> <li class="nav-item"><a class="nav-link" href="#">Pricing</a></li> <li class="nav-item dropdown position-static"> <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown">Dropdown link</a> <ul class="dropdown-menu start-0 end-0 border-0 rounded-0 shadow-sm mt-2"> <li> <div class="container"> <div class="row"> <div class="col-md-4"> <nav class="nav flex-column"> <a class="nav-link" href="#">Link 1</a> <a class="nav-link" href="#">Link 2</a> <a class="nav-link" href="#">Link 3</a> <a class="nav-link" href="#">Link 4</a> <a class="nav-link disabled" href="#">Disabled</a> </nav> </div> <div class="col-md-4"> <nav class="nav flex-column"> <a class="nav-link" href="#">Link 5</a> <a class="nav-link" href="#">Link 6</a> <a class="nav-link" href="#">Link 7</a> <a class="nav-link" href="#">Link 8</a> <a class="nav-link disabled" href="#">Disabled</a> </nav> </div> <div class="col-md-4"> <nav class="nav flex-column"> <a class="nav-link" href="#">Link 9</a> <a class="nav-link" href="#">Link 10</a> <a class="nav-link" href="#">Link 11</a> <a class="nav-link" href="#">Link 12</a> <a class="nav-link disabled" href="#">Disabled</a> </nav> </div> </div> </div> </li> </ul> </li> </ul> </div> </div> </nav> </header> <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"></script> </body> </html> |
How It Works
- The menu item that acts as the mega menu is wrapped in a
.dropdown
and usesposition-static
so the dropdown stretches full width. - The
.dropdown-menu
usesstart-0 end-0
to go edge-to-edge. - Inside the dropdown, we use a
.container > .row > .col-md-4
structure to create three columns of links. - The
nav flex-column
classes stack links vertically in each column.
🔍 Understanding the Mega Menu Dropdown Code
Here’s the snippet we’re focusing on:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <li class="nav-item dropdown position-static"> <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown link </a> <ul class="dropdown-menu start-0 end-0 border-0 rounded-0 shadow-sm mt-2"> <li> <div class="container"> <div class="row"> <div class="col-md-4"> <nav class="nav flex-column"> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </nav> </div> <div class="col-md-4"> <nav class="nav flex-column"> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </nav> </div> <div class="col-md-4"> <nav class="nav flex-column"> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link" href="#">Link</a> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </nav> </div> </div> </div> </li> </ul> </li> |
Let’s go section by section.
🧱 li.nav-item.dropdown.position-static
This is the parent <li>
element for the mega menu dropdown.
.nav-item
— This is part of the navbar’s item list..dropdown
— Tells Bootstrap this is a dropdown..position-static
— Makes sure the dropdown isn’t positioned absolutely, which is important for mega menus to expand properly across the width of the navbar.
🔗 <a class="nav-link dropdown-toggle">
This is the clickable dropdown link that opens the mega menu.
.nav-link
— Styles the link like a normal navbar item..dropdown-toggle
— Enables the toggle behavior with Bootstrap JS.data-bs-toggle="dropdown"
— Required for Bootstrap’s dropdown to activate.aria-expanded="false"
— Indicates the menu is initially closed (important for accessibility).
📦 <ul class="dropdown-menu start-0 end-0 ...">
This is the dropdown content container.
.dropdown-menu
— Styles it as a dropdown..start-0 end-0
— Makes the dropdown full width of the parent container..border-0
,.rounded-0
,.shadow-sm
— Customize the appearance..mt-2
— Adds spacing below the toggle button.
Inside this <ul>
, we place one big <li>
that holds our grid layout.
🧩 <div class="container">
and Grid Layout
We wrap our content in .container > .row > .col-md-4
structure to create 3 equal-width columns in the dropdown.
Each column uses:
1 2 3 4 5 6 | <nav class="nav flex-column"> <a class="nav-link" href="#">Link</a> ... </nav> |
.nav.flex-column
— Stacks links vertically inside the column..nav-link
— Applies Bootstrap’s consistent nav styling..disabled
+aria-disabled="true"
— Makes a link visibly disabled.
You can replace each column with categories like “Products”, “Resources”, or even include images or icons.
📐 Resulting Layout
This structure gives you:
✅ A full-width dropdown
✅ Three evenly spaced columns
✅ A clean, responsive layout
✅ Easy to customize with more links, images, or even components
💡 Customization Ideas
- Use
.container-fluid
to make the dropdown even wider. - Add headings to each column (
<h6 class="text-uppercase fw-bold">Category</h6>
). - Drop in a small product card or image preview.
Bonus Tips
- Add icons next to links using Font Awesome or Bootstrap Icons.
- You can add images, buttons, or even forms inside the mega menu columns.
- Customize the width by replacing
.container
with.container-fluid
.
✅ Conclusion
Creating a mega menu with Bootstrap 5 is easier than ever, thanks to the power of its grid system and flexible utility classes. You now have a multi-column dropdown that looks great and works on both desktop and mobile.
You can now customize it for your project — add categories, icons, even featured products or articles!