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 component. Resize the browser to preview responsive behavior.
<NavbarDemo
bodyClassName="mb-2 md:mb-0"
brand="Navbar"
className="bg-1"
expand="md"
placement="end"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Link
</NavLink>
</NavItem>
<NavItem>
<Menu
label="Menu"
nav
>
<MenuItem href="#">
Action
</MenuItem>
<MenuItem href="#">
Another action
</MenuItem>
<MenuDivider />
<MenuItem href="#">
Something else here
</MenuItem>
</Menu>
</NavItem>
<NavItem>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</NavItem>
</NavbarNav>
<Stack
as={function ve(){}}
direction="horizontal"
gap={2}
role="search"
>
<FormControl
aria-label="Search"
placeholder="Search"
type="search"
/>
<Button
icon
theme="secondary"
type="submit"
variant="solid"
>
<Icon
aria-hidden
name="search"
/>
</Button>
</Stack>
</NavbarDemo>How it works
Here’s what you need to know before getting started with the navbar:
- Use
Navbaras the root, setexpandto control the responsive breakpoint, and setthemeto choose its color scheme. - 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.
Navbarrenders a semantic<nav>landmark by default. If you change its element withas, provide an appropriate navigation landmark.- Indicate the current item by using
aria-current="page"for the current page oraria-current="true"for the current item in a set.
The animation effect depends on the
prefers-reduced-motionmedia query. See the reduced motion accessibility guidance.
Supported content
Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:
NavbarBrandfor your company, product, or project name.NavbarNavfor lightweight navigation links, including menus.NavbarTogglerfor navigation toggling and drawer behaviors.- Flex and spacing utilities for any form controls and actions.
NavbarTextfor vertically centered text.
Brand
Use NavbarBrand for a brand name or link. It renders an anchor by default; set as="span" when the brand is not a link.
Text
Pass the brand text as NavbarBrand's children.
<>
<Navbar className="bg-1 fg-2">
<Container fluid>
<NavbarBrand href="#">
Navbar
</NavbarBrand>
</Container>
</Navbar>
<Navbar className="bg-1 fg-2">
<Container fluid>
<NavbarBrand
as="span"
className="mb-0 h1"
>
Navbar
</NavbarBrand>
</Container>
</Navbar>
</>Image
Place an Image inside NavbarBrand to use an image as the brand.
<Navbar className="bg-1 fg-2">
<Container>
<NavbarBrand href="#">
<Image
alt="Bootstrap"
height="24"
src="https://getbootstrap.com/docs/6.0/assets/brand/bootstrap-logo.svg"
width="30"
/>
</NavbarBrand>
</Container>
</Navbar>Image and text
To combine an image and text, place both inside NavbarBrand and pass layout utilities through the Image component's className.
<Navbar className="bg-1 fg-2">
<Container fluid>
<NavbarBrand href="#">
<Image
alt="Logo"
className="d-inline-block align-text-top"
height="24"
src="https://getbootstrap.com/docs/6.0/assets/brand/bootstrap-logo.svg"
width="30"
/>
{' '}Bootstrap{' '}
</NavbarBrand>
</Container>
</Navbar>Nav
NavbarNav contains NavLink items and supports navigation variants. Set Navbar's expand prop for responsive layout. Navigation in navbars also grows to occupy horizontal space to keep the contents aligned.
Set active on NavLink to indicate the current page.
Also set aria-current="page" on the active NavLink.
<NavbarDemo
brand="Navbar"
className="bg-1 fg-2"
expand="sm"
placement="end"
title="Menu"
togglerFirst={false}
>
<NavbarNav>
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Features
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Pricing
</NavLink>
</NavItem>
<NavItem>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</NavItem>
</NavbarNav>
</NavbarDemo>And because we use classes for our navs, you can avoid the list-based approach entirely if you like.
<NavbarDemo
brand="Navbar"
className="bg-1 fg-2"
expand="sm"
placement="end"
title="Menu"
togglerFirst={false}
>
<Nav
navbar
variant="pills"
>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
<NavLink href="#">
Features
</NavLink>
<NavLink href="#">
Pricing
</NavLink>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</Nav>
</NavbarDemo>You can also use menus in your navbar. Wrap each menu in NavItem for its positioning, as shown below.
<NavbarDemo
brand="Navbar"
className="bg-1 fg-2"
expand="lg"
placement="end"
title="Menu"
togglerFirst={false}
>
<NavbarNav>
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Features
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Pricing
</NavLink>
</NavItem>
<NavItem>
<Menu
label="Menu link"
nav
>
<MenuItem href="#">
Action
</MenuItem>
<MenuItem href="#">
Another action
</MenuItem>
<MenuItem href="#">
Something else here
</MenuItem>
</Menu>
</NavItem>
</NavbarNav>
</NavbarDemo>Forms
Place various form controls and components within a navbar:
<Navbar className="bg-1 fg-2">
<Container fluid>
<Form
className="d-flex"
role="search"
>
<FormControl
aria-label="Search"
className="me-2"
placeholder="Search"
type="search"
/>
<Button
theme="success"
type="submit"
variant="outline"
>
Search
</Button>
</Form>
</Container>
</Navbar>Immediate child elements of Navbar use flex layout and default to justify-content: space-between.
Use additional flex utilities as needed to adjust this behavior.
<Navbar className="bg-1 fg-2">
<Container fluid>
<NavbarBrand>
Navbar
</NavbarBrand>
<Form
className="d-flex"
role="search"
>
<FormControl
aria-label="Search"
className="me-2"
placeholder="Search"
type="search"
/>
<Button
theme="success"
type="submit"
variant="outline"
>
Search
</Button>
</Form>
</Container>
</Navbar>Input groups work, too. If the navbar is primarily a form, use the Form wrapper as its container.
<Navbar className="bg-1 fg-2">
<Container fluid>
<InputGroup>
<InputGroupText id="basic-addon1">
@
</InputGroupText>
<FormControl
aria-describedby="basic-addon1"
aria-label="Username"
placeholder="Username"
type="text"
/>
</InputGroup>
</Container>
</Navbar>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.
<Navbar className="bg-1 fg-2">
<Container
className="justify-content-start"
fluid
>
<Button
className="me-2"
theme="success"
variant="outline"
>
Main button
</Button>
<Button
size="sm"
theme="secondary"
variant="outline"
>
Smaller button
</Button>
</Container>
</Navbar>Text
Use NavbarText for text in a navbar; it adjusts vertical alignment and horizontal spacing.
<Navbar className="bg-1 fg-2">
<Container fluid>
<NavbarText>
{' '}Navbar text with an inline element{' '}
</NavbarText>
</Container>
</Navbar>Mix and match with other components and utilities as needed.
<NavbarDemo
brand="Navbar w/ text"
className="bg-1 fg-2"
expand="md"
placement="end"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto mb-2 md:mb-0">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Features
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Pricing
</NavLink>
</NavItem>
</NavbarNav>
<NavbarText>
{' '}Navbar text with an inline element{' '}
</NavbarText>
</NavbarDemo>Dark navbar
To make a navbar dark, set theme="dark" on Navbar.
<NavbarDemo
bodyClassName="mb-2 md:mb-0"
brand="Dark navbar"
className="bg-1"
expand="md"
placement="end"
theme="dark"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Link
</NavLink>
</NavItem>
<NavItem>
<Menu
label="Menu"
nav
>
<MenuItem href="#">
Action
</MenuItem>
<MenuItem href="#">
Another action
</MenuItem>
<MenuDivider />
<MenuItem href="#">
Something else here
</MenuItem>
</Menu>
</NavItem>
<NavItem>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</NavItem>
</NavbarNav>
<Stack
as={function ve(){}}
direction="horizontal"
gap={2}
role="search"
>
<FormControl
aria-label="Search"
placeholder="Search"
type="search"
/>
<Button
icon
theme="secondary"
type="submit"
variant="solid"
>
<Icon
aria-hidden
name="search"
/>
</Button>
</Stack>
</NavbarDemo>Translucent navbar
Set translucent to blur and saturate the background of a navbar. This works well for navbars positioned over content, such as fixed or sticky navbars.
Content behind the navbar
The translucent navbar blurs and saturates this background content.
<div className="position-relative overflow-hidden rounded bg-primary text-white">
<Navbar
className="position-absolute top-0 start-0 w-100"
expand
theme="dark"
translucent
>
<Container fluid>
<NavbarBrand href="#">
Navbar
</NavbarBrand>
<NavbarNav>
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Features
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Pricing
</NavLink>
</NavItem>
</NavbarNav>
</Container>
</Navbar>
<div className="p-5 pt-5">
<h3>
Content behind the navbar
</h3>
<p className="mb-0">
The translucent navbar blurs and saturates this background content.
</p>
</div>
</div>Color schemes
Navbar themes use Bootstrap's 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.
<>
<NavbarDemo
brand="Navbar"
expand="md"
placement="end"
theme="dark"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto mb-2 md:mb-0">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Features
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Pricing
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
About
</NavLink>
</NavItem>
</NavbarNav>
<Form
className="d-flex"
role="search"
>
<FormControl
aria-label="Search"
className="me-2"
placeholder="Search"
type="search"
/>
<Button
theme="secondary"
type="submit"
variant="outline"
>
Search
</Button>
</Form>
</NavbarDemo>
<NavbarDemo
brand="Navbar"
className="bg-primary"
expand="md"
placement="end"
theme="dark"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto mb-2 md:mb-0">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Features
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Pricing
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
About
</NavLink>
</NavItem>
</NavbarNav>
<Form
className="d-flex"
role="search"
>
<FormControl
aria-label="Search"
className="me-2"
data-bs-theme="light"
placeholder="Search"
type="search"
/>
<Button
theme="inverse"
type="submit"
variant="solid"
>
Search
</Button>
</Form>
</NavbarDemo>
<NavbarDemo
brand="Navbar"
className="bg-1"
expand="md"
placement="end"
theme="light"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto mb-2 md:mb-0">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Features
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Pricing
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
About
</NavLink>
</NavItem>
</NavbarNav>
<Form
className="d-flex"
role="search"
>
<FormControl
aria-label="Search"
className="me-2"
placeholder="Search"
type="search"
/>
<Button
theme="primary"
type="submit"
variant="outline"
>
Search
</Button>
</Form>
</NavbarDemo>
</><Navbar theme="dark" />
<Navbar theme="dark" className="bg-primary" />
<Navbar theme="light" className="bg-1" />
Containers
Although it’s not required, you can wrap Navbar in a Container to center it on a page, or place a
Container inside Navbar to center only its contents. An inner Container is required for a
fixed or static top navbar.
<Container>
<Navbar
className="bg-1 fg-2"
expand="lg"
>
<Container fluid>
<NavbarBrand href="#">
Navbar
</NavbarBrand>
</Container>
</Navbar>
</Container>Use any of the responsive containers to change how wide the content in your navbar is presented.
<Navbar
className="bg-1 fg-2"
expand="lg"
>
<Container fluid="md">
<NavbarBrand href="#">
Navbar
</NavbarBrand>
</Container>
</Navbar>Placement
Use our position utilities to place navbars in non-static positions. Choose from fixed to the top, fixed to the bottom, stickied to the top (scrolls with the page until it reaches the top, then stays there), or stickied to the bottom (scrolls with the page until it reaches the bottom, then stays there).
Fixed navbars use position: fixed, meaning they’re pulled from the normal flow of the DOM and may require custom CSS (e.g., padding-top on the <body>) to prevent overlap with other elements.
<Navbar className="bg-1">
<Container fluid>
<NavbarBrand href="#placement">Default</NavbarBrand>
</Container>
</Navbar>Responsive behaviors
Navbars use NavbarToggler and the expand prop to determine when their content appears in a drawer or inline. Pass a breakpoint such as expand="md"; in combination with other utilities, you can easily choose when to show or hide particular elements.
For navbars that never collapse, use expand={true}. For navbars that always show the drawer, use expand={false}.
Drawer
By default, navbars use the drawer component for their responsive behavior. This provides a modern drawer-style menu that slides in from any side of the screen.
Drawer placement
You can customize which side the drawer appears from using its placement prop:
"start"- slides in from the left (or right in RTL)"end"- slides in from the right (or left in RTL)"top"- slides in from the top"bottom"- slides in from the bottom
These examples show the drawer below the md breakpoint. Click the toggler on a narrow screen to see it slide in from different directions.
<NavbarDemo
brand="Left Drawer"
className="bg-1 fg-2"
expand="md"
placement="start"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto mb-2 md:mb-0">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Link
</NavLink>
</NavItem>
<NavItem>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</NavItem>
</NavbarNav>
</NavbarDemo><NavbarDemo
brand="Top Drawer"
className="bg-1 fg-2"
expand="md"
placement="top"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto mb-2 md:mb-0">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Link
</NavLink>
</NavItem>
<NavItem>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</NavItem>
</NavbarNav>
</NavbarDemo>Toggler
Navbar togglers are left-aligned by default, but when placed after a sibling such as NavbarBrand, they automatically align to the far right. Reversing the component order reverses the toggler placement.
The first example collapses below the md breakpoint; the following examples always keep the toggler visible. Click it to open the drawer.
To toggle inline content outside the responsive navbar examples, pass its selector to CollapseToggle with the navbarToggler prop:
<Navbar className="bg-1 fg-2">
<NavbarBrand href="#">
Navbar
</NavbarBrand>
<CollapseToggle
aria-label="Toggle navigation"
navbarToggler
target="#navbarContent"
variant={false}
/>
<Collapse id="navbarContent">
Navbar content
</Collapse>
</Navbar>With no brand shown in the navbar (the brand is hidden inside the drawer):
<NavbarDemo
brand={null}
className="bg-1 fg-2"
expand="md"
placement="end"
title="Hidden brand"
togglerFirst
>
<NavbarBrand href="#">
Hidden brand
</NavbarBrand>
<NavbarNav className="me-auto mb-2 md:mb-0">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Link
</NavLink>
</NavItem>
<NavItem>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</NavItem>
</NavbarNav>
<Form
className="d-flex"
role="search"
>
<FormControl
aria-label="Search"
className="me-2"
placeholder="Search"
type="search"
/>
<Button
theme="success"
type="submit"
variant="outline"
>
Search
</Button>
</Form>
</NavbarDemo>With a brand name shown on the left and toggler on the right:
<NavbarDemo
brand="Navbar"
className="bg-1 fg-2"
expand={false}
placement="end"
title="Menu"
togglerFirst={false}
>
<NavbarNav className="me-auto mb-2">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Link
</NavLink>
</NavItem>
<NavItem>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</NavItem>
</NavbarNav>
<Form
className="d-flex"
role="search"
>
<FormControl
aria-label="Search"
className="me-2"
placeholder="Search"
type="search"
/>
<Button
theme="success"
type="submit"
variant="outline"
>
Search
</Button>
</Form>
</NavbarDemo>With a toggler on the left and brand name on the right:
<NavbarDemo
brand="Navbar"
className="bg-1 fg-2"
expand={false}
placement="end"
title="Menu"
togglerFirst
>
<NavbarNav className="me-auto mb-2">
<NavItem>
<NavLink
active
aria-current="page"
href="#"
>
Home
</NavLink>
</NavItem>
<NavItem>
<NavLink href="#">
Link
</NavLink>
</NavItem>
<NavItem>
<NavLink
aria-disabled="true"
disabled
>
Disabled
</NavLink>
</NavItem>
</NavbarNav>
<Form
className="d-flex"
role="search"
>
<FormControl
aria-label="Search"
className="me-2"
placeholder="Search"
type="search"
/>
<Button
theme="success"
type="submit"
variant="outline"
>
Search
</Button>
</Form>
</NavbarDemo>External content
Sometimes you want to use the drawer 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!
<NavbarExternalDemo />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.
CSS
Variables
Use CSS custom properties on the component to customize its appearance without recompiling Bootstrap.
.navbar {
--bs-navbar-padding-x: 0;
--bs-navbar-padding-y: 0.5rem;
--bs-navbar-min-height: 3.5rem;
--bs-navbar-color: var(--bs-fg-2);
--bs-navbar-hover-color: var(--bs-fg-1);
--bs-navbar-disabled-color: var(--bs-fg-3);
--bs-navbar-active-color: var(--bs-fg-body);
--bs-navbar-brand-margin-end: 1rem;
--bs-navbar-brand-font-size: var(--bs-font-size-md);
--bs-navbar-brand-font-weight: var(--bs-font-weight-medium);
--bs-navbar-brand-color: var(--bs-fg-body);
--bs-navbar-brand-hover-color: var(--bs-fg-body);
--bs-navbar-nav-link-padding-x: 0.75rem;
--bs-navbar-toggler-width: 2rem;
--bs-navbar-toggler-padding-y: 0.25rem;
--bs-navbar-toggler-padding-x: 0.75rem;
--bs-navbar-toggler-font-size: var(--bs-font-size-lg);
--bs-navbar-toggler-border-color: color-mix(in oklch, var(--bs-fg-body) 15%, transparent);
--bs-navbar-toggler-border-radius: var(--bs-radius-5);
--bs-navbar-toggler-transition: box-shadow 0.15s ease-in-out;
--bs-navbar-toggler-icon-size: 1.25rem;
--bs-navbar-toggler-icon: #{escape-svg(
url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path stroke='black' stroke-linecap='round' stroke-width='1' d='M1 3.5h14M1 8h14M1 12.5h14'/></svg>")
)};
}
.navbar {
--bs-navbar-color: color-mix(in oklch, var(--bs-white) 55%, transparent);
--bs-navbar-hover-color: color-mix(in oklch, var(--bs-white) 75%, transparent);
--bs-navbar-disabled-color: color-mix(in oklch, var(--bs-white) 25%, transparent);
--bs-navbar-active-color: var(--bs-white);
--bs-navbar-brand-color: var(--bs-white);
--bs-navbar-brand-hover-color: var(--bs-white);
--bs-navbar-toggler-border-color: color-mix(in oklch, var(--bs-white) 10%, transparent);
}
.navbar {
--bs-nav-gap: 0.25rem;
--bs-nav-link-gap: 0.5rem;
--bs-nav-link-padding-x: 0.5rem;
--bs-nav-link-padding-y: 0.375rem;
--bs-nav-link-color: var(--bs-navbar-color);
--bs-nav-link-border-width: var(--bs-border-width);
--bs-nav-link-hover-color: var(--bs-navbar-hover-color);
--bs-nav-link-hover-bg: transparent;
--bs-nav-link-active-color: var(--bs-navbar-active-color);
--bs-nav-link-active-bg: transparent;
--bs-nav-link-disabled-color: var(--bs-navbar-disabled-color);
}