HTML

How to Create a Mega Menu with Bootstrap 5

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:

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.

How to Create a Mega Menu with Bootstrap 5

✅ Full HTML Code

How It Works

  • The menu item that acts as the mega menu is wrapped in a .dropdown and uses position-static so the dropdown stretches full width.
  • The .dropdown-menu uses start-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:

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:

  • .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!

Leave a Comment