Navbar
Source: https://getbootstrap.com/docs/6.0/components/navbar
Create flexible, responsive navigation bars. Includes support for branding, navigation, and a built-in drawer for mobile.
Example
Here’s a navbar that includes most supported sub-components and a responsive right drawer with our Drawer plugin. Use the lower-right corner grip to resize to preview responsive behavior.
<div class="container-fluid"> <a class="navbar-brand" href="#">Navbar</a> <button class="btn-icon navbar-toggler" type="button" data-bs-toggle="drawer" data-bs-target="#navbarDrawer" aria-controls="navbarDrawer" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon" aria-hidden="true"></span> </button> <dialog class="drawer drawer-end" tabindex="-1" id="navbarDrawer" aria-labelledby="navbarDrawerLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="navbarDrawerLabel">Menu</h5> </div> <div class="drawer-body mb-2 md:mb-0"> <ul class="nav navbar-nav me-auto"> <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="#">Link</a> </li> <li class="nav-item"> <button class="nav-link" type="button" data-bs-toggle="menu" aria-expanded="false"> Menu </button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <hr class="menu-divider"> <a class="menu-item" href="#">Something else here</a> </div> </li> <li class="nav-item"> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </li> </ul> <form class="hstack gap-2" role="search"> <input class="form-control" type="search" placeholder="Search" aria-label="Search"/> <button class="btn-solid btn-icon theme-secondary" type="submit"> <svg class="bi" width="16" height="16"><use href="#search" /></svg> </button> </form> </div> </dialog> </div> </nav>`} />
How it works
Here’s what you need to know before getting started with the navbar:
- Navbars require a wrapping
.navbarwith.{breakpoint}:navbar-expand(e.g..md:navbar-expand) for responsive collapsing and color scheme classes. - Navbars and their contents are fluid by default. Change the container to limit their horizontal width in different ways.
- Use our margin, padding, and flex utility classes for controlling spacing and alignment within navbars.
- Navbars are responsive by default using our drawer component. On mobile, navigation links slide in from the side as a drawer.
- 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. - Indicate the current item by using
aria-current="page"for the current page oraria-current="true"for the current item in a set.
Supported content
Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:
.navbar-brandfor your company, product, or project name..navbar-navfor a full-height and lightweight navigation (including support for menus)..navbar-togglerfor use with our drawer plugin and other navigation toggling behaviors.- Flex and spacing utilities for any form controls and actions.
.navbar-textfor adding vertically centered strings of text.
Brand
The .navbar-brand can be applied to most elements, but an anchor works best, as some elements might require utility classes or custom styles.
Text
Add your text within an element with the .navbar-brand class.
<nav class="navbar bg-1 fg-2"> <div class="container-fluid"> <a class="navbar-brand" href="#">Navbar</a> </div> </nav>
<!-- As a heading --> <nav class="navbar bg-1 fg-2"> <div class="container-fluid"> <span class="navbar-brand mb-0 h1">Navbar</span> </div> </nav>`} />
Image
You can replace the text within the .navbar-brand with an <img>.
<div class="container"> <a class="navbar-brand" href="#"> <img src="/docs/${getConfig().docs_version}/assets/brand/bootstrap-logo.svg" alt="Bootstrap" width="30" height="24"> </a> </div> </nav>`} />
Image and text
You can also make use of some additional utilities to add an image and text at the same time. Note the addition of .d-inline-block and .align-text-top on the <img>.
<div class="container-fluid"> <a class="navbar-brand" href="#"> <img src="/docs/${getConfig().docs_version}/assets/brand/bootstrap-logo.svg" alt="Logo" width="30" height="24" class="d-inline-block align-text-top"> Bootstrap </a> </div> </nav>`} />
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.
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.
<div class="container-fluid"> <a class="navbar-brand" href="#">Navbar</a> <button class="btn-icon navbar-toggler" type="button" data-bs-toggle="drawer" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon" aria-hidden="true"></span> </button> <dialog class="drawer drawer-end" tabindex="-1" id="navbarNav" aria-labelledby="navbarNavLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="navbarNavLabel">Menu</h5> </div> <div class="drawer-body"> <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="#">Features</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Pricing</a> </li> <li class="nav-item"> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </li> </ul> </div> </dialog> </div> </nav>`} />
And because we use classes for our navs, you can avoid the list-based approach entirely if you like.
<div class="container-fluid"> <a class="navbar-brand" href="#">Navbar</a> <button class="btn-icon navbar-toggler" type="button" data-bs-toggle="drawer" data-bs-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon" aria-hidden="true"></span> </button> <dialog class="drawer drawer-end" tabindex="-1" id="navbarNavAltMarkup" aria-labelledby="navbarNavAltMarkupLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="navbarNavAltMarkupLabel">Menu</h5> </div> <div class="drawer-body"> <div class="nav nav-pills navbar-nav"> <a class="nav-link active" aria-current="page" href="#">Home</a> <a class="nav-link" href="#">Features</a> <a class="nav-link" href="#">Pricing</a> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </div> </div> </dialog> </div> </nav>`} />
You can also use menus in your navbar. 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.
<div class="container-fluid"> <a class="navbar-brand" href="#">Navbar</a> <button class="btn-icon navbar-toggler" type="button" data-bs-toggle="drawer" data-bs-target="#navbarNavMenu" aria-controls="navbarNavMenu" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon" aria-hidden="true"></span> </button> <dialog class="drawer drawer-end" tabindex="-1" id="navbarNavMenu" aria-labelledby="navbarNavMenuLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="navbarNavMenuLabel">Menu</h5> </div> <div class="drawer-body"> <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="#">Features</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Pricing</a> </li> <li class="nav-item"> <button class="nav-link" type="button" data-bs-toggle="menu" aria-expanded="false"> Menu link </button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <a class="menu-item" href="#">Something else here</a> </div> </li> </ul> </div> </dialog> </div> </nav>`} />
Forms
Place various form controls and components within a navbar:
<div class="container-fluid"> <form class="d-flex" role="search"> <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"/> <button class="btn-outline theme-success" type="submit">Search</button> </form> </div> </nav>`} />
Immediate child elements of .navbar use flex layout and will default to justify-content: space-between. Use additional flex utilities as needed to adjust this behavior.
<div class="container-fluid"> <a class="navbar-brand">Navbar</a> <form class="d-flex" role="search"> <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search"/> <button class="btn-outline theme-success" type="submit">Search</button> </form> </div> </nav>`} />
Input groups work, too. If your navbar is an entire form, or mostly a form, you can use the <form> element as the container and save some HTML.
<form class="container-fluid"> <div class="input-group"> <span class="input-group-text" id="basic-addon1">@</span> <input type="text" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1"/> </div> </form> </nav>`} />
Various buttons are supported as part of these navbar forms, too. This is also a great reminder that vertical alignment utilities can be used to align different sized elements.
<form class="container-fluid justify-content-start"> <button class="btn-outline theme-success me-2" type="button">Main button</button> <button class="btn-outline theme-secondary btn-sm" type="button">Smaller button</button> </form> </nav>`} />
Text
Navbars may contain bits of text with the help of .navbar-text. This class adjusts vertical alignment and horizontal spacing for strings of text.
<div class="container-fluid"> <span class="navbar-text"> Navbar text with an inline element </span> </div> </nav>`} />
Mix and match with other components and utilities as needed.
<div class="container-fluid"> <a class="navbar-brand" href="#">Navbar w/ text</a> <button class="btn-icon navbar-toggler" type="button" data-bs-toggle="drawer" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon" aria-hidden="true"></span> </button> <dialog class="drawer drawer-end" tabindex="-1" id="navbarText" aria-labelledby="navbarTextLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="navbarTextLabel">Menu</h5> </div> <div class="drawer-body"> <ul class="navbar-nav me-auto mb-2 md:mb-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="#">Features</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Pricing</a> </li> </ul> <span class="navbar-text"> Navbar text with an inline element </span> </div> </dialog> </div> </nav>`} />
Dark navbar
To make a navbar dark, add data-bs-theme="dark" to the .navbar element.
<div class="container-fluid"> <a class="navbar-brand" href="#">Dark navbar</a> <button class="btn-icon navbar-toggler" type="button" data-bs-toggle="drawer" data-bs-target="#navbarDarkDrawer" aria-controls="navbarDarkDrawer" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon" aria-hidden="true"></span> </button> <dialog class="drawer drawer-end" tabindex="-1" id="navbarDarkDrawer" aria-labelledby="navbarDarkDrawerLabel"> <div class="drawer-header"> <h5 class="drawer-title" id="navbarDarkDrawerLabel">Menu</h5> </div> <div class="drawer-body mb-2 md:mb-0"> <ul class="nav navbar-nav me-auto"> <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="#">Link</a> </li> <li class="nav-item"> <button class="nav-link" type="button" data-bs-toggle="menu" aria-expanded="false"> Menu </button> <div class="menu"> <a class="menu-item" href="#">Action</a> <a class="menu-item" href="#">Another action</a> <hr class="menu-divider"> <a class="menu-item" href="#">Something else here</a> </div> </li> <li class="nav-item"> <a class="nav-link disabled" aria-disabled="true">Disabled</a> </li> </ul> <form class="hstack gap-2" role="search"> <input class="form-control" type="search" placeholder="Search" aria-label="Search"/> <button class="btn-solid btn-icon theme-secondary" type="submit"> <svg class="bi" width="16" height="16"><use href="#search" /></svg> </button> </form> </div> </dialog> </div> </nav>`} />
Translucent navbar
Add .navbar-translucent to blur and saturate the background of a navbar. This works well for navbars positioned over content, such as fixed or sticky navbars.
<div class="container-fluid"> <a class="navbar-brand" href="#">Navbar</a> <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="#">Features</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Pricing</a> </li> </ul> </div> </nav>`} />
Color schemes
Navbar themes are easier than ever thanks to Bootstrap’s combination of Sass and CSS variables. The default is our "light navbar" for use with light background colors, but you can also apply data-bs-theme="dark" to the .navbar parent for dark background colors. Then, customize with .bg-* and additional utilities.
