Menu
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.
Do you know the latest update of 2022? Our roadmap is alive for future updates.
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.
Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:
.navbar-brand
for your company, product, or project name.
.navbar-nav
for a full-height and lightweight navigation (including support for dropdowns).
.navbar-toggler
for use with our collapse plugin and other navigation toggling behaviors.
.navbar-text
for adding vertically centered strings of text.
.collapse.navbar-collapse
for grouping and hiding navbar contents by a parent breakpoint.
.navbar-scroll
to set a max-height
and scroll expanded navbar content.
Here’s an example of all the sub-components included in a responsive light-themed navbar that automatically collapses at the lg
(large) breakpoint.
Add your text within an element with the .navbar-brand
class.
You can replace the text within the .navbar-brand
with an <img>
.
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.
Add the .active
class on .nav-link
to indicate the current page.
Please note that you should also add the aria-current
attribute on the active .nav-link
.
You can also use dropdowns in your navbar. 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.
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.
Add .navbar-nav-scroll
to a .navbar-nav
(or other navbar sub-component) to enable vertical scrolling within the toggleable contents of a collapsed navbar. By default, scrolling kicks in at 75vh
(or 75% of the viewport height), but you can override that with the local CSS custom property --bs-navbar-height
or custom styles. At larger viewports when the navbar is expanded, content will appear as it does in a default navbar.
Please note that this behavior comes with a potential drawback of overflow
—when setting overflow-y: auto
(required to scroll the content here), overflow-x
is the equivalent of auto
, which will crop some horizontal content.
Here’s an example navbar using .navbar-nav-scroll
with style="--bs-scroll-height: 100px;"
, with some extra margin utilities for optimum spacing.
Navbar togglers are left-aligned by default, but should they follow a sibling element like a .navbar-brand
, they’ll automatically be aligned to the far right. Reversing your markup will reverse the placement of the toggler. Below are examples of different toggle styles.
With no .navbar-brand
shown at the smallest breakpoint:
With a brand name shown on the left and toggler on the right:
With a toggler on the left and brand name on the right:
Sometimes you want to use the collapse plugin to trigger a container element for content that structurally sits outside of the .navbar
. Because our plugin works on the id
and data-bs-target
matching, that’s easily done!
When you do this, we recommend including additional JavaScript to move the focus programmatically to the container when it is opened. Otherwise, keyboard users and users of assistive technologies will likely have a hard time finding the newly revealed content - particularly if the container that was opened comes before the toggler in the document’s structure. We also recommend making sure that the toggler has the aria-controls
attribute, pointing to the id
of the content container. In theory, this allows assistive technology users to jump directly from the toggler to the container it controls–but support for this is currently quite patchy.