Ask any question about CSS here... and get an instant response.
Post this Question & Answer:
How can I create a responsive navbar that collapses into a hamburger menu on smaller screens?
Asked on May 03, 2026
Answer
To create a responsive navbar that collapses into a hamburger menu on smaller screens, you can use Bootstrap's built-in classes and components. This approach allows you to leverage Bootstrap's responsive utilities to manage the navbar's behavior across different screen sizes.
<!-- BEGIN COPY / PASTE -->
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Brand</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></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">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
</li>
</ul>
</div>
</nav>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.3/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- END COPY / PASTE -->Additional Comment:
- The "navbar-expand-lg" class ensures the navbar expands on large screens and collapses on smaller ones.
- The "navbar-toggler" button triggers the collapse functionality, showing the hamburger icon on smaller screens.
- Ensure to include Bootstrap's CSS and JS files, as well as jQuery and Popper.js for the collapse functionality to work.
- Customize the navbar by adding or removing list items and changing the "navbar-brand" text.
Recommended Links:
