Navbar
The component BNavbar is a wrapper that positions branding, navigation, and other elements into a concise header. It is easily extensible and thanks to the BCollapse component, it can easily integrate responsive behaviors.
Color schemes
BNavbar supports the standard Bootstrap v5 available background color variants. Set the variant prop to one of the following values to change the background color: primary, secondary, success, info, warning, danger, dark, light, or any of the *-subtle variants.
If the variant prop is set, it may be necessary to control the text color so that it contrasts with the variant irrespective of the theme. This can be done by using the v-b-color-mode directive or useColorMode composable
The example below uses v-b-colorMode. For more information see the BColorMode directive.
BNavbar will conform to the current color theme if the variant prop is not set.
Placement
Control the placement of the navbar by setting one of two props:
| prop | type | default | description |
|---|---|---|---|
fixed | Extract<Placement, 'top' | 'bottom'> | undefined | Set to top for fixed to the top of the viewport, or bottom for fixed to the bottom of the viewport. |
sticky | Extract<Placement, 'top' | 'bottom'> | undefined | Set to true to make the navbar stick to the top of the viewport (or parent container that has position: relative set) when scrolled. |
Notes:
- Fixed positioning uses CSS
position: fixed. You may need to adjust your document top/bottom padding or margin. - CSS
position: sticky(used forsticky) is not fully supported in every browser. For browsers that do not supportposition: sticky, it will fallback natively toposition: relative.
Supported content
Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:
BNavbarBrandfor your company, product, or project name.BNavbarTogglefor use with the<BCollapse is-nav>component.<BCollapse is-nav>for grouping and hiding navbar contents by a parent breakpoint.BNavbarNavfor a full-height and lightweight navigation (including support for dropdowns). The following sub-components insideBNavbarNavare supported:BNavItemfor link (and router-link) action itemsBNavItemDropdownfor nav dropdown menusBNavTextfor adding vertically centered strings of text.BNavFormfor any form controls and actions.
BNavbarBrand
The BNavbarBrand generates a link if href is provided, or a RouterLink if to is provided. If neither is given it renders as a <div> tag. You can override the tag type by setting the tag prop to the element you would like rendered:
Adding images to the BNavbarBrand will likely always require custom styles or utilities to properly size. Here are some examples to demonstrate:
BNavbarNav
Navbar navigation links build on the BNavbarNav parent component and requires the use of <BCollapse is-nav> and <-toggle> toggler 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.
BNavbarNav supports the following child components:
BNavItemfor link (and router-link) action itemsBNavTextfor adding vertically centered strings of text.BNavItemDropdownfor navbar dropdown menusBNavFormfor adding simple forms to the navbar.
BNavItem
BNavItem is the primary link (and RouterLink) component. Providing a to prop value will generate a RouterLink while providing an href prop value will generate a standard link.
Set the BNavItem active prop will highlight the item as being the active page, Disable a BNavItem by setting the prop disabled to true.
Handle click events by specifying a handler for the @click event on BNavItem.
BNavText
Navbars may contain bits of text with the help of BNavText. This component adjusts vertical alignment and horizontal spacing for strings of text.
BNavItemDropdown
For BNavItemDropdown usage, see the BDropdown docs. Note split dropdowns are not supported in BNavbar and BNavbarNav.
BNavForm
Use BNavForm to place inline form controls into your navbar. See BNavForm docs for details.
Input Groups work as well:
BNavbarToggle and <BCollapse is-nav>
Navbars are not responsive by default, but you can easily modify them to change that. Responsive behavior depends on our BCollapse component.
Wrap BNavbarNav components in a <BCollapse is-nav> (remember to set the is-nav prop!) to specify content that will collapse based on a particular breakpoint. Assign a document unique id value on the BCollapse.
Use the BNavbarToggle component to control the collapse component, and set the target prop of BNavbarToggle to the id of BCollapse.
Set the toggleable prop on BNavbar to the desired breakpoint you would like content to automatically expand at. Possible toggleable values are sm, md, lg and xl. Setting toggleable to true (or an empty string) will set the navbar to be always collapsed, while setting it to false (the default) will disable collapsing (always expanded).
BNavbarToggle components are left-aligned by default, but should they follow a sibling element like BNavbarBrand, they'll automatically be aligned to the far right. Reversing your markup will reverse the placement of the toggler.
See the first example on this page for reference, and also refer to BCollapse for details on the collapse component.
Besides being used to control a collapse, the BNavbarToggle can also be used to toggle visibility of the BSidebar component. Just specify the ID of the BSidebar via the target prop.
Internally, BNavbarToggle uses the v-b-toggle directive.
Custom navbar toggle
BNavbarToggle renders the default Bootstrap v5 hamburger (which is a background SVG image). You can supply your own content (such as an icon) via the optionally scoped default slot. The default slot scope contains the property expanded, which will be true when the collapse is expanded, or false when the collapse is collapsed.
Note that the expanded scope property only works when supplying the target prop as a string, and not an array.
Offcanvas
Transform your expanding and collapsing navbar into an offcanvas drawer with the BOffoffcanvas component.
In the example below, to create an offcanvas navbar that is always collapsed across all breakpoints, set toggleable='true'.
Scrolling
Add .navbar-nav-scroll to the Navbar (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), see the bootstrap documentation for details on overriding.
Auto close behavior
By default, the collapsible component is closed when clicking inside or outside the dropdown menu. You can use the auto-close property to change this behavior of the collapsible component.
The auto-closeproperty has 4 options.
true: the collapsible component will be closed by clicking outside or inside the collapsible componentfalse: the collapsible component will be closed by clicking the toggle button and manually calling the hide method. (Also will not be closed by pressing esc key)inside: the collapsible component will be closed (only) by clicking inside the collapsible component menuoutside: the collapsible component will be closed (only) by clicking outside the dropdown menu
Printing
Navbars are hidden by default when printing. Force them to be printed by setting the print prop.
See also
BCollapsecomponentBSidebarcomponent- v-b-toggle directive
BNavdocumentation for additional components and sub-component aliases Refer to the Router support reference page for router-link specific props.
Component Reference
<BNavbar>
| Prop | Type | Default | Description |
|---|---|---|---|
| container | boolean | 'fluid' | Breakpoint | 'fluid' | Use the container option to change the layout of the navbar. By default, the navbar is a fluid container. Use 'fluid' for a full width navbar, or a responsive breakpoint for a container width navbar. |
| fixed | 'top' | 'bottom' | undefined | Set to 'top' for fixed to the top of the viewport, or 'bottom' for fixed to the bottom of the viewport |
| no-auto-close | boolean | false | Disable auto-closing of the navbar when a child component is clicked |
boolean | false | Navbars are hidden by default when printing. When this prop is set it will be printed | |
| sticky | 'top' | 'bottom' | undefined | Set to 'true' to make the navbar stick to the top of the viewport (or parent container that has 'position: relative' set) when scrolled |
| tag | string | 'nav' | Specify the HTML tag to render instead of the default tag |
| toggleable | boolean | Breakpoint | false | Set to 'true' for an always collapsed navbar, or to a specific breakpoint at which point the navbar will be expanded: 'sm', 'md', 'lg', 'xl', or 'xxl' |
| variant | ColorVariant | null | null | Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence |
| Name | Scope | Description |
|---|---|---|
| default | Content to place in the navbar |
<BNavbarBrand>
.navbar‑brand| Prop | Type | Default | Description |
|---|---|---|---|
| tag | string | 'ul' | Specify the HTML tag to render instead of the default tag |
| Name | Scope | Description |
|---|---|---|
| default | Content to place in the navbar brand |
<BNavbarNav>
.navbar‑nav| Prop | Type | Default | Description |
|---|---|---|---|
| align | AlignmentJustifyContent | undefined | Align the nav items in the nav: 'start', 'end', 'center', 'between', 'around', or 'evenly' |
| fill | boolean | false | Proportionately fills all horizontal space with nav items. All horizontal space is occupied, but not every nav item has the same width |
| justified | boolean | false | Fills all horizontal space with nav items, but unlike 'fill', every nav item will be the same width |
| small | boolean | false | Makes the nav smaller |
| tag | string | 'ul' | Specify the HTML tag to render instead of the default tag |
| Name | Scope | Description |
|---|---|---|
| default | Content to place in the navbar nav |
<BNavbarToggle>
.navbar‑toggle| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | false | When set to `true`, disables the component's functionality and places it in a disabled state |
| label | string | 'Toggle navigation' | String to place in the toggle's 'aria-label' attribute |
| target | string | readonly string[] | undefined | ID (or array of IDs) of the collapse/sidebar components that should be toggled |
| Event | Args | Description |
|---|---|---|
| click | click: MouseEvent - Native mouse event object | Emitted when the toggle is clicked |
| Name | Scope | Description |
|---|---|---|
| default | Alternate content to replace the default Bootstrap hamburger |