Building a Responsive Navigation Bar with React‑Bootstrap
Learn how to create a responsive navigation bar that collapses into a hamburger menu using React-Bootstrap, with a working example and verification steps.
22 Feb 2026, 17:41 UTC

Problem: Navigation breaks on small screens
When a React app is viewed on a phone, the top menu stays visible, forcing users to scroll horizontally. The goal is a hamburger menu that appears only below a certain width.
Solution: Use React‑Bootstrap's Navbar
The Navbar component automatically collapses into a hamburger menu below the xs breakpoint (≤576 px). It handles the CSS media queries and the JavaScript toggle for you.
Key Features
- Responsive collapse handled by the library.
- Fully accessible dropdown items with ARIA attributes.
- Container width options: fluid, static, fixed.
- Easy conditional rendering for authenticated vs. guest users.
Worked Example
Below is a minimal component that creates a responsive Navbar. Run it in a Create‑React‑App project with React‑Bootstrap 2.x.
import React, { useState } from 'react';
import { Navbar, Nav, NavDropdown, Button } from 'react-bootstrap';
function ResponsiveNavbar() {
const [showMenu, setShowMenu] = useState(false);
return (
MyApp
Dashboard
Profile
Orders
Settings
setShowMenu(!showMenu)}>
{showMenu ? 'Hide' : 'Show'} Menu
);
}
export default ResponsiveNavbar;
Key points in the code:
- The
expand="lg"prop tells the Navbar to stay horizontal onlgand larger screens and collapse below that. Navbar.Togglerenders the hamburger icon; clicking it toggles the collapse.- All dropdown items are automatically accessible because
NavDropdownuses ARIA roles.
Verification Steps
- Start the dev server:
npm start(requires a user with Node.js and the project dependencies installed). - Resize the browser window or open Chrome DevTools device toolbar. Confirm the menu collapses when the viewport width is ≤576 px and expands above that width.
- Inspect an item in the collapsed menu. Verify that the
aria-haspopup="true"andaria-expandedattributes change as the menu opens and closes. - Run
npm list react-bootstrapto ensure the installed version is 2.x or newer; older versions lack the built-in responsive toggles.
Limitations
- If you set
expand="xs"the menu never collapses, which can be confusing on very wide screens. - Heavy custom CSS that overrides the Navbar's
displayorflexproperties may break the automatic collapse behavior, making future upgrades painful. - Older React-Bootstrap releases (<1.0) require manual media-query handling; using a recent version avoids that extra work.
Practical Check
After implementing the component, open the page on a mobile device or use the responsive mode in Firefox DevTools. The hamburger icon should appear, and tapping it should reveal the navigation links without horizontal scrolling. If the menu stays open, double-check the expand prop and any custom styles that might affect the collapse class.
Closing
React-Bootstrap's Navbar gives you a production-ready, accessible, and responsive navigation bar with minimal code. By respecting the default breakpoints and avoiding deep CSS overrides, you can achieve a reliable UI that works across devices and remains easy to maintain.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.