Course Content
Bootstrap 5 Alerts
0/1
Progress Bars
0/1
Spinners
0/1
Pagination
0/1
List Groups
0/1
Bootstrap 5 Scrollspy
0/1
Bootstrap
About Lesson

Responsive Navbar with Toggler

  • .navbar-toggler → Creates the menu button
  • .navbar-collapse → Wraps the collapsible content
  • .collapse → Hides content until toggled

Example: Responsive Navbar

HTML
<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container">
    <a class="navbar-brand" href="#">Brand</a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarNav">
      <ul class="navbar-nav">
        <li class="nav-item"><a class="nav-link" href="#">Home</a></li>
        <li class="nav-item"><a class="nav-link" href="#">Services</a></li>
      </ul>
    </div>
  </div>
</nav>

Output:

Explanation:

  • .navbar-toggler creates a hamburger menu.
  • .collapse hides the menu on smaller screens.