Category: html_css
Responsive Navbar
Published on 06 Aug 2026
Explanation
The Bootstrap Responsive Navbar is a navigation component that automatically adapts to different screen sizes. On larger screens, navigation links are displayed horizontally, while on smaller devices they collapse into a hamburger menu that users can expand.
Code:
Explanation
A Bootstrap Navbar typically consists of a navbar container, brand, navigation links, toggler button, and collapsible menu. The `navbar-expand-lg` class determines when the menu expands based on the screen size.
Code:
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="#">MyWebsite</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 ms-auto">
<li class="nav-item"><a class="nav-link active" href="#">Home</a></li>
<li class="nav-item"><a class="nav-link" href="#">About</a></li>
<li class="nav-item"><a class="nav-link" href="#">Services</a></li>
<li class="nav-item"><a class="nav-link" href="#">Contact</a></li>
</ul>
</div>
</div>
</nav>
Explanation
Bootstrap provides responsive expansion classes to control when the navigation menu becomes horizontal. Choose the appropriate class based on your layout requirements:
• navbar-expand-sm
• navbar-expand-md
• navbar-expand-lg
• navbar-expand-xl
• navbar-expand-xxl
Without an expand class, the navbar always remains collapsed.
Code:
<nav class="navbar navbar-expand-md navbar-light bg-light"> <!-- Navbar explanation --> </nav>
Explanation
Navbar utilities allow you to align navigation links, add spacing, include forms, buttons, and dropdown menus. Classes like `ms-auto`, `me-auto`, and `justify-explanation-*` help position navbar items easily.
Code:
<ul class="navbar-nav ms-auto">
<li class="nav-item"><a class="nav-link" href="#">Login</a></li>
<li class="nav-item ms-2">
<button class="btn btn-primary">Sign Up</button>
</li>
</ul>
Explanation
The responsive navbar can include branding, search bars, dropdowns, and action buttons to build professional navigation menus for modern web applications. Ensure the Bootstrap JavaScript bundle is included so the collapse and toggler functionality works correctly.
Code:
<form class="d-flex me-3"> <input class="form-control me-2" type="search" placeholder="Search"> <button class="btn btn-outline-success" type="submit">Search</button> </form> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>