Navbars
A powerful, responsive navigation header, the navbar. Includes support for branding, navigation, and more
Overview
Hereโs what you need to know before getting started with the Navbar:
- Use the
expand
prop to allow for collapsing the Navbar at lower breakpoints. - Navbars and their contents are fluid by default. Use optional containers to limit their horizontal width.
- Use spacing and flex utilities to size and position content
A responsive navigation header, including support for branding, navigation, and more. Hereโs an example of all the sub-components included in a responsive light-themed navbar that automatically collapses at the lg (large) breakpoint.
Brand
A simple flexible branding component. Images are supported but will likely require custom styling to work well.
Forms
Text and Non-nav links
Loose text and links can be wrapped Navbar.Text
in order to correctly align it vertically.
Color schemes
Theming the navbar has never been easier thanks to the combination of theming classes and background-color utilities. Choose from variant="light"
for use with light background colors, or variant="dark"
for dark background colors. Then, customize with the bg
prop or any custom css!
Containers
While not required, you can wrap the Navbar in a <Container>
component to center it on a page, or add one within to only center the contents of a fixed or static top navbar.
When the container is within your navbar, its horizontal padding is removed at breakpoints lower than your specified expand={'sm' | 'md' | 'lg' | 'xl' | 'xxl'}
prop. This ensures weโre not doubling up on padding unnecessarily on lower viewports when your navbar is collapsed.
Placement
You can use Bootstrap's position utilities to place navbars in non-static positions. Choose from fixed to the top, fixed to the bottom, or stickied to the top (scrolls with the page until it reaches the top, 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. Also note that .sticky-top
uses position: sticky
, which isnโt fully supported in every browser.
Since these positioning needs are so common for Navbars, we've added convenience props for them
Fixed top
<Navbar fixed="top" />
Fixed bottom
<Navbar fixed="bottom" />
Sticky top
<Navbar sticky="top" />
Scrolling
You can use the navbarScroll
prop in a <Nav>
to enable vertical scrolling within the toggleable contents of a collapsed navbar. See the Bootstrap docs for more information.
Responsive behaviors
Use the expand
prop as well as the Navbar.Toggle
and Navbar.Collapse
components to control when content collapses behind a button.
Set the defaultExpanded
prop to make the Navbar start expanded. Set collapseOnSelect
to make the Navbar collapse automatically when the user selects an item. You can also finely control the collapsing behavior by using the expanded
and onToggle
props.
API
Navbarview source file
import Navbar from 'react-bootstrap/Navbar'
Copy import code for the Navbar componentName | Type | Default | Description |
---|---|---|---|
as | elementType | Set a custom element for this component. | |
bg | string | A convenience prop for adding Pairs nicely with the | |
collapseOnSelect | boolean | false | Toggles Manually controlling |
expand | true | 'sm' | 'md' | 'lg' | 'xl' | 'xxl' | true | The breakpoint, below which, the Navbar will collapse.
When |
expanded | boolean | controlled by: onToggle , initial prop: defaultExpanded Controls the visiblity of the navbar body | |
fixed | 'top' | 'bottom' | Create a fixed navbar along the top or bottom of the screen, that scrolls with the
page. A convenience prop for the | |
onSelect | function | A callback fired when a descendant of a child
For basic closing behavior after all Note: If you are manually closing the navbar using this | |
onToggle | function | controls expanded A callback fired when the | |
role | string | 'navigation' | The ARIA role for the navbar, will default to 'navigation' for
Navbars whose |
sticky | 'top' | Position the navbar at the top of the viewport, but only after scrolling past it.
A convenience prop for the Not supported in <= IE11 and other older browsers without a polyfill | |
variant | 'light' | 'dark' | 'light' | The general visual variant a the Navbar.
Use in combination with the |
bsPrefix | string | 'navbar' | Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css. |
Navbar.Brandview source file
import Navbar from 'react-bootstrap/Navbar'
Copy import code for the Navbar componentName | Type | Default | Description |
---|---|---|---|
as | elementType | Set a custom element for this component. | |
href | string | An href, when provided the Brand will render as an | |
bsPrefix | string | 'navbar' | Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css. |
Navbar.Toggleview source file
import Navbar from 'react-bootstrap/Navbar'
Copy import code for the Navbar componentName | Type | Default | Description |
---|---|---|---|
as | elementType | <button> | You can use a custom element type for this component. |
children | node | The toggle content. When empty, the default toggle will be rendered. | |
label | string | 'Toggle navigation' | An accessible ARIA label for the toggler button. |
onClick | function | ||
bsPrefix | string | 'navbar-toggler' | Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css. |
Navbar.Collapseview source file
import Navbar from 'react-bootstrap/Navbar'
Copy import code for the Navbar componentName | Type | Default | Description |
---|---|---|---|
bsPrefix | string | 'navbar-collapse' | Change the underlying component CSS base class name and modifier class names prefix. This is an escape hatch for working with heavily customized bootstrap css. |