Navbar
Documentation and examples for Bootstrap's powerful, responsive navigation header, the navbar. Includes support for branding, navigation, and more, including support for our collapse plugin.
How it works
Here’s what you need to know before getting started with the navbar:
- Navbars require a wrapping
.navbar
with.navbar-expand{-sm|-md|-lg|-xl}
for responsive collapsing and color scheme classes. - Navbars and their contents are fluid by default. Use optional containers to limit their horizontal width.
- Use spacing and flex utility classes for controlling spacing and alignment within navbars.
- Navbars are responsive by default, but you can easily modify them to change that. Responsive behavior depends on our Collapse JavaScript plugin.
- Navbars are hidden by default when printing. Force them to be printed by adding
.d-print
to the.navbar
. See the display utility class. - Ensure accessibility by using a
<nav>
element or, if using a more generic element such as a<div>
, add arole="navigation"
to every navbar to explicitly identify it as a landmark region for users of assistive technologies.
Read on for an example and list of supported sub-components.
Nav
Navbar navigation links build on our .nav
options with their own modifier class and require the use of toggler classes for proper responsive styling. Navigation in navbars will also grow to occupy as much horizontal space as possible to keep your navbar contents securely aligned.
Active states—with .active
—to indicate the current page can be applied directly to .nav-link
s or their immediate parent .nav-item
s.
<nav class="navbar navbar-expand-lg bg-primary">
<div class="container">
<div class="navbar-wrapper">
<a class="navbar-brand" href="javascript:;">Navbar</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation" data-target="#navbarNav">
<span class="sr-only">Toggle navigation</span>
<span class="navbar-toggler-icon icon-bar"></span>
<span class="navbar-toggler-icon icon-bar"></span>
<span class="navbar-toggler-icon icon-bar"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="javascript:;">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:;">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:;">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:;">About</a>
</li>
</ul>
</div>
</div>
</nav>
You may also utilize dropdowns in your navbar nav. Dropdown menus require a wrapping element for positioning, so be sure to use separate and nested elements for .nav-item
and .nav-link
as shown below.
<nav class="navbar navbar-expand-lg bg-primary">
<div class="container">
<div class="navbar-wrapper">
<a class="navbar-brand" href="javascript:;">Navbar</a>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" aria-controls="navbarDropdown" aria-expanded="false" aria-label="Toggle navigation" data-target="#navbarDropdown">
<span class="sr-only">Toggle navigation</span>
<span class="navbar-toggler-icon icon-bar"></span>
<span class="navbar-toggler-icon icon-bar"></span>
<span class="navbar-toggler-icon icon-bar"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarDropdown">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="javascript:;">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:;">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:;">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="javascript:;">About</a>
</li>
</ul>
</div>
</div>
</nav>
Color schemes
Theming the navbar has never been easier thanks to the combination of theming classes and background-color
utilities. Choose from .navbar-light
for use with light background colors, or .navbar-dark
for dark background colors. Then, customize with .bg-*
utilities.
Containers
When the container is within your navbar, its horizontal padding is removed at breakpoints lower than your specified .navbar-expand{-sm|-md|-lg|-xl}
class. This ensures we’re not doubling up on padding unnecessarily on lower viewports when your navbar is collapsed.
<nav class="navbar navbar-expand-lg navbar-light bg-primary">
<div class="container">
<a class="navbar-brand" href="javascript:;">Navbar</a>
</div>
</nav>
Responsive behaviors
Navbars can utilize .navbar-toggler
, .navbar-collapse
, and .navbar-expand{-sm|-md|-lg|-xl}
classes to change when their content collapses behind a button. In combination with other utilities, you can easily choose when to show or hide particular elements.
For navbars that never collapse, add the .navbar-expand
class on the navbar. For navbars that always collapse, don’t add any .navbar-expand
class.