Navigation Bar
Give your website direction. Learn to build a polished, responsive Bootstrap navigation bar with branding, links, active states, and a mobile-friendly menu.
<nav class="navbar navbar-expand-lg"> <a class="navbar-brand"> MyWebsite </a> ... </nav>
What Is a Navigation Bar?
A navigation bar, often called a navbar, helps visitors find their way around a website. It commonly appears at the top of a page and contains the website’s name, logo, and important links.
Bootstrap provides a ready-made navbar component that adapts to different screen sizes. On large screens, links can appear side by side. On smaller screens, the same links can collapse behind a menu button.
Create Your First Navbar
Bootstrap uses the navbar class as
the foundation. Add a background class and
a container to give the navigation bar its structure.
<nav class="navbar bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="#">
MyWebsite
</a>
</div>
</nav>
navbar
Activates Bootstrap’s navigation bar styling.
navbar-brand
Styles the website name or brand link.
container-fluid
Allows the navbar content to span the available width.
bg-body-tertiary
Applies a subtle background using Bootstrap’s theme colors.
Add Menu Items
A useful navbar needs links. Bootstrap uses
navbar-nav for the link collection,
nav-item for each item, and
nav-link for the actual links.
<ul class="navbar-nav">
<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="#about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#contact">Contact</a>
</li>
</ul>
The active class highlights the current
page. The aria-current="page" attribute
communicates the current page to assistive technology.
Make Your Navbar Mobile-Friendly
One of Bootstrap’s most useful features is its
responsive navigation. The class
navbar-expand-lg means the menu expands
horizontally at Bootstrap’s large breakpoint
(992px and above).
Below that width, you can display a hamburger button that opens and closes the navigation links.
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="#">MyWebsite</a>
<button class="navbar-toggler" type="button"
data-bs-toggle="collapse"
data-bs-target="#mainMenu"
aria-controls="mainMenu"
aria-expanded="false"
aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="mainMenu">
<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="#about">About</a>
</li>
</ul>
</div>
</div>
</nav>
navbar-expand-lg
Shows the expanded navigation at large screen sizes.
navbar-toggler
Styles the button that opens the mobile menu.
data-bs-toggle="collapse"
Tells Bootstrap to toggle a collapsible element.
navbar-collapse
Groups the navigation links inside the collapsible area.
data-bs-target="#mainMenu" must match
the collapse element’s id="mainMenu".
The Bootstrap JavaScript bundle is also required
for the menu to open and close.
Customize Navbar Colors
Bootstrap includes background utilities and color modes that make navbar customization easier. For example, you can create a dark navigation bar with light-colored text.
<nav class="navbar navbar-expand-lg bg-dark"
data-bs-theme="dark">
<!-- Your navbar content -->
</nav>
You can also experiment with
bg-primary, bg-light,
or bg-body-tertiary.
Use data-bs-theme="dark" when you
want Bootstrap’s navbar colors and toggle icon
to suit a dark background.
Align Your Navigation Links
Bootstrap spacing utilities help control where navbar content appears.
<ul class="navbar-nav ms-auto">
<!-- Navigation items -->
</ul>
The ms-auto class applies automatic
margin at the start side, pushing the menu toward
the end of the navbar in a standard left-to-right layout.
You can also use me-auto to push
following content away, and gap-2
to create spacing between elements.
🚀 mC0de Challenge
Build a Responsive Website Header
Imagine you’re creating a website for a small creative studio. Your task is to build a professional navigation bar that works on desktop and mobile.
Your mission: Complete all five tasks below.
The checklist is for self-review. Use the Sandbox to experiment, and load the sample solution when you’re ready.
mC0de Bootstrap Sandbox
Edit your navbar, run the code, and switch between desktop and mobile previews.
What You’ve Learned
- The
navbarclass provides Bootstrap's navigation foundation. navbar-brandstyles the website's brand or name.navbar-nav,nav-item, andnav-linkorganize navigation links.- The
activeclass andaria-current="page"identify the current page. navbar-expand-lgcontrols the responsive breakpoint.navbar-togglerandcollapse navbar-collapsecreate a mobile menu.- Bootstrap's JavaScript bundle powers the hamburger toggle.
- Background, color mode, and spacing utilities help customize navbar appearance.
Up next: We'll learn how to create interactive Bootstrap Dropdown menus.
Your Learning Journey
0 of 7 completedNice Work! 🎉
You've learned how to build a responsive Bootstrap navigation bar with links, branding, and a working mobile menu. Ready to record your progress?


