The Navigation Bar (Navbar) is the primary header component on modern websites. It provides branding, direct navigation links to key sections, interactive dropdown menus, search inputs, and an automatic hamburger toggle button on mobile viewports. In Bootstrap 5, navbars are built on CSS Flexbox and require zero jQuery to operate.
A production Bootstrap navbar consists of five essential sub-components:
1. .navbar & .navbar-expand-*: The outer wrapper that establishes flexbox alignment and specifies at which breakpoint the menu expands horizontally (e.g. .navbar-expand-lg expands on ≥992px, collapsing on smaller screens).
2. .navbar-brand: For company logos, project names, or text branding.
3. .navbar-toggler: The hamburger button that appears on mobile viewports to toggle the collapsed menu.
4. .collapse.navbar-collapse: The collapsible container grouping navigation links together.
5. .navbar-nav: The lightweight list of links (.nav-link) and dropdowns.
Here is a production-ready navbar with branding, active links, dropdown menus, and a search form:
<nav class="navbar navbar-expand-lg bg-body-tertiary shadow-sm">
<div class="container">
<!-- 1. Brand Logo -->
<a class="navbar-brand fw-bold text-primary" href="#">
<img src="images/logo.png" width="30" height="30" class="d-inline-block align-text-top me-2" alt="Logo">
Veewom
</a>
<!-- 2. Mobile Hamburger Toggle Button -->
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNavbarNav" aria-controls="mainNavbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<!-- 3. Collapsible Links Container -->
<div class="collapse navbar-collapse" id="mainNavbarNav">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Tutorials</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Languages
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="../html/">HTML5</a></li>
<li><a class="dropdown-item" href="../css/">CSS3</a></li>
<li><a class="dropdown-item" href="../bootstrap/">Bootstrap 5</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="../react/">React JS</a></li>
</ul>
</li>
</ul>
<!-- 4. Search Form on Right Edge -->
<form class="d-flex" role="search">
<input class="form-control me-2" type="search" placeholder="Search topics..." aria-label="Search">
<button class="btn btn-outline-primary" type="submit">Search</button>
</form>
</div>
</div>
</nav>
Notice that the data-bs-target="#mainNavbarNav" attribute on the <button> must exactly match the id="mainNavbarNav" on the collapsible <div>! If the ID and target do not match, clicking the hamburger icon will fail to expand the menu.
Create sleek dark navigation headers using data-bs-theme="dark", and lock the navbar to the top of the viewport during scrolling using .fixed-top or .sticky-top:
<!-- Dark Theme Fixed Navbar -->
<nav class="navbar navbar-expand-lg bg-dark fixed-top" data-bs-theme="dark">
<div class="container">
<a class="navbar-brand" href="#">Dark Navbar</a>
...
</div>
</nav>
Strengthen your responsive web design mastery by studying these connected classes:
Explore in-page navigation links, vertical pills, and tabbed panels.
Transform the mobile navbar toggle into a smooth sliding drawer.
Embed multi-level and responsive dropdown menus into the navbar.
Use data-bs-theme='dark' to create sleek dark navigation headers.
.me-auto sets margin-right: auto; on the navigation link list (.navbar-nav), pushing all subsequent sibling items (like the search form or login buttons) completely to the right edge of the navbar.
.sticky-top utility class instead of .fixed-top. sticky-top scrolls normally with the page until it touches the top of the viewport, where it locks into position.
.collapse.navbar-collapse with .offcanvas.offcanvas-end.
Advance your practical frontend engineering skills with the next topic in our synchronized curriculum.
Continue to Class 19: Navs, Tabs & Pills → Previous: ← Class 17: Form Validation | Full Syllabus