Nav
Navigation available in Bootstrap share general markup and styles, from the base <BNav>
class to the active
and disabled
states. Swap modifier props to switch between each style.
<BNav>
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItem>Another Link</BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
Overview
The base <BNav>
component is built with flexbox and provides a strong foundation for building all types of navigation components. It includes some style overrides (for working with lists), some link padding for larger hit areas, and basic disabled styling. No active states are included in the base nav.
<BNav>
supports the following child components:
<BNavItem>
for actionable links (or router-links)<BNavItemDropdown>
for dropdowns<BNavText>
for plain text content<BNavForm>
for inline forms
Link appearance
Two style variations are supported: tabs
and pills
, which support active
state styling. These variants are mutually exclusive - use only one style or the other.
Tab style
Make the nav look like tabs by setting the tabs
prop.
<BNav tabs>
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItem>Another Link</BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
Pill style
Use the pill style by setting the pills
prop.
<BNav pills>
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItem>Another Link</BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
Small
Make the nav smaller by setting the small
prop.
<BNav small>
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItem>Another Link</BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
Fill and justify
Force your <BNav>
content to extend the full available width.
Fill
To proportionately fill all available space with your <BNavItem>
components, set the fill
prop. Notice that all horizontal space is occupied, but not every nav item has the same width.
<BNav tabs fill>
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItem>Link with a long name </BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
Justified
For equal-width elements, set the justified
prop instead. All horizontal space will be occupied by nav links, but unlike fill
above, every <BNavItem>
will be the same width.
<BNav tabs justified>
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItem>Link with a long name </BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
Alignment
To align your <BNavItem>
components, use the align
prop. Available values are those from AlignmentJustifyContent
: start
, center
, end
, between
, around
, and evenly
.
<BNav tabs align="center">
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItem>Link with a long name </BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
Vertical variation
By default <BNav>
appear on a horizontal line. Stack your navigation by setting the vertical
prop.
<BNav vertical class="w-25">
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItem>Another Link</BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
Dropdown support
Use <BNavItemDropdown>
to place dropdown items within your nav.
<BNav pills>
<BNavItem active>Active</BNavItem>
<BNavItem>Link</BNavItem>
<BNavItemDropdown id="my-nav-dropdown" text="Dropdown" toggle-class="nav-link-custom" right>
<BDropdownItem>One</BDropdownItem>
<BDropdownItem>Two</BDropdownItem>
<BDropdownDivider />
<BDropdownItem>Three</BDropdownItem>
</BNavItemDropdown>
</BNav>
Sometimes you want to add your own class names to the generated dropdown toggle button, that by default have the classes nav-link
and dropdown-toggle
. Use the toggle-class
prop to add them (like above) which will render HTML similar to:
<li id="my-nav-dropdown" class="nav-item b-nav-dropdown dropdown">
<a role="button" href="#my-nav-dropdown" id="my-nav-dropdown__BV_button_" aria-haspopup="true" aria-expanded="false"
class="nav-link dropdown-toggle nav-link-custom"></a>
...
</li>
Refer to <BDropdown>
for a list of supported sub-components.
Optionally scoped default slot
The dropdown default slot is optionally scoped with the following scope available:
Property or Method | Description |
---|---|
hide() | Can be used to close the dropdown menu. |
show() | Can be used to show the dropdown menu. |
Lazy dropdown
By default, <BNavItemDropdown>
renders the menu contents in the DOM even when the menu is not shown. When there are a large number of dropdowns rendered on the same page, performance could be impacted due to larger overall memory utilization. You can instruct <BNavItemDropdown>
to render the menu contents only when it is shown by setting the lazy
prop to true.
Dropdown placement
Use the start
, end
, center
, placement
, no-flip
, and offset
to control the positioning of <BNavItemDropdown>
.
Refer to the <BDropdown>
positioning section for details on the effects and usage of these props.
Dropdown implementation note
Note that the toggle button is actually rendered as a link <a>
tag with role="button"
for styling purposes, and typically has the href
set to #
unless an ID is provided via the id
prop.
The toggle will prevent scroll-top-top behaviour (via JavaScript) when clicking the toggle link. In some cases when using SSR, and the user clicks the toggle button before Vue has had a chance to hydrate the component, the page will scroll to top. In these cases, simply providing a unique ID via the id
prop will prevent the unwanted scroll-to-top behaviour.
Dropdown Exposed Methods
<BNavItemDropdown>
exposes the same methods as <BDropdown>
, see the dropdown documentation for details.
Nav text content
Use the <BNavText>
child component to place plain text content into the nav:
<BNav>
<BNavItem href="#1">Link 1</BNavItem>
<BNavItem href="#2">Link 2</BNavItem>
<BNavText>Plain text</BNavText>
</BNav>
Nav inline forms
Use the <BNavForm>
child component to place an inline form into the nav:
<template>
<BNav pills class="mb-1">
<BNavItem href="#1" active>Link 1</BNavItem>
<BNavItem href="#2">Link 2</BNavItem>
<BNavForm @submit.stop.prevent="submitted = true">
<BFormInput aria-label="Input" class="mr-1" />
<BButton class="ms-2" type="submit">Ok</BButton>
</BNavForm>
</BNav>
<span v-if="submitted">Form Submitted</span>
</template>
<script setup lang="ts">
import {ref} from 'vue'
const submitted = ref(false)
</script>
Refer to the <BForm>
inline documentation for additional details on placing form controls.
Tabbed local content support
See the <BTabs>
component for creating tabbable panes of local content (not suited for navigation).
Card integration
Use a <BNav>
in a <BCard>
header, by enabling the card-header
prop on <BNav>
and setting either the pills
or tabs
props:
Tabs style:
With supporting text below as a natural lead-in to additional content.
<BCard title="Card Title" no-body>
<BCardHeader header-tag="nav">
<BNav card-header tabs>
<BNavItem active>Active</BNavItem>
<BNavItem>Inactive</BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
</BCardHeader>
<BCardBody class="text-center">
<BCardText>
With supporting text below as a natural lead-in to additional content.
</BCardText>
<BButton variant="primary">Go somewhere</BButton>
</BCardBody>
</BCard>
Pill style:
With supporting text below as a natural lead-in to additional content.
<BCard title="Card Title" no-body>
<BCardHeader header-tag="nav">
<BNav card-header pills>
<BNavItem active>Active</BNavItem>
<BNavItem>Inactive</BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
</BCardHeader>
<BCardBody class="text-center">
<BCardText>
With supporting text below as a natural lead-in to additional content.
</BCardText>
<BButton variant="primary">Go somewhere</BButton>
</BCardBody>
</BCard>
Plain style:
The card-header
prop is only needed when you are applying tabs
or pills
style. Note that Bootstrap v5 SCSS does not have special styling for active
state plain style nav items.
With supporting text below as a natural lead-in to additional content.
<BCard title="Card Title" no-body>
<BCardHeader header-tag="nav">
<BNav>
<BNavItem active>Active</BNavItem>
<BNavItem>Inactive</BNavItem>
<BNavItem disabled>Disabled</BNavItem>
</BNav>
</BCardHeader>
<BCardBody class="text-center">
<BCardText>
With supporting text below as a natural lead-in to additional content.
</BCardText>
<BButton variant="primary">Go somewhere</BButton>
</BCardBody>
</BCard>
The card-header
prop has no styling effect if the <BNav>
is in vertical
mode.
Using with Vue Router
Have your card <BNav>
control vue router nested routes via <router-view>
or <nuxt-child>
components, to created tabbed content that changes with route URL:
<!-- On page with route `/some/route` -->
<BCard title="Card Title" no-body>
<BCardHeader header-tag="nav">
<BNav card-header tabs>
<!-- <BNavItem>'s with child routes. Note the trailing slash on the first <BNavItem> -->
<BNavItem to="/some/route/" exact exact-active-class="active">Active</BNavItem>
<BNavItem to="/some/route/foo" exact exact-active-class="active">Foo</BNavItem>
<BNavItem to="/some/route/bar" exact exact-active-class="active">Bar</BNavItem>
</BNav>
</BCardHeader>
<BCardBody>
<!-- Child route gets rendered in <RouterView> or <NuxtPage> -->
<RouterView />
<!-- Or if using Nuxt.js
<NuxtPage />
-->
</BCardBody>
</BCard>
INFO
Vue Router does not support defining active routes with hashes (#
), which is why you must define the "tab" content as child routes.
Example router config for above:
/* eslint-disable @typescript-eslint/no-unused-vars */
const routes = [
{
path: '/some/route',
// We don't provide a name on this parent route, but rather
// set the name on the default child route instead
// name: 'some-route',
component: SomeRouteComponent,
// Child route "tabs"
children: [
// Note we provide the above parent route name on the default child tab
// route to ensure this tab is rendered by default when using named routes
{path: '', component: DefaultTabComponent, name: 'some-route'},
{path: 'foo', component: FooTabComponent},
{path: 'bar', component: BarTabComponent},
],
},
]
One can also use Vue Router named routes and/or route params instead of path based routes.
For more details see:
Component Reference
<BNav>
Prop | Type | Default | Description |
---|---|---|---|
align | AlignmentJustifyContent | undefined | Align the nav items in the nav to any value of AlignmentJustifyContent |
card-header | boolean | false | Set this prop when the nav is placed inside a card header |
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 |
pills | boolean | false | Renders the nav items with the appearance of pill buttons |
small | boolean | false | Makes the nav smaller |
tabs | boolean | false | Renders the nav items with the appearance of tabs |
tag | string | 'ul' | Specify the HTML tag to render instead of the default tag |
underline | boolean | false | Adds an underline to the active nav item |
vertical | boolean | false | Stacks the nav items vertically |
Name | Scope | Description |
---|---|---|
default | Content to place in the nav |
<BNavForm>
Prop | Type | Default | Description |
---|---|---|---|
floating | boolean | false | When set, renders a single control form with a floating label. This only works for forms where the immediate children are a label and one of the supported controls. See above for details. |
form-class | ClassValue | undefined | CSS class (or classes) to add to the form element |
id | string | undefined | Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed |
novalidate | boolean | false | When set, disables browser native HTML5 validation on controls in the form |
role | string | undefined | Sets the ARIA attribute `role` to a specific value |
validated | boolean | false | When set, adds the Bootstrap class 'was-validated' on the form, triggering the native browser validation states |
wrapper-attrs | Readonly<AttrsValue> | undefined | Attributes to be applied to the wrapper element |
Event | Args | Description |
---|---|---|
submit | submit : Event - Native submit event | Emitted when the form is submitted |
Name | Scope | Description |
---|---|---|
default | Content to place in the nav form |
<BNavItem>
Prop | Type | Default | Description |
---|---|---|---|
link-attrs | Readonly<AttrsValue> | undefined | Additional attributes to place on the nested link element |
link-class | ClassValue | undefined | CSS class (or classes) to place on the nested link element |
Event | Args | Description |
---|---|---|
click | click : MouseEvent - On click event | Emitted when non-disabled nav item clicked |
Name | Scope | Description |
---|---|---|
default | Content to place in the nav item |
<BNavItemDropdown>
.nav‑item.dropdown
Prop | Type | Default | Description |
---|---|---|---|
aria-label | string | undefined | Sets the value of `aria-label` attribute on the rendered element |
auto-close | boolean | 'inside' | 'outside' | true | Controls the automatic closing of the dropdown when clicking. See above for details. |
boundary | Boundary | RootBoundary | 'clippingAncestors' | The boundary constraint of dropdown: any value of floating-us's Boundary or RootBoundary type. See above for details. |
boundary-padding | Padding | undefined | The virtual padding around the boundary to check for overflow |
disabled | boolean | false | When set to `true`, disables the component's functionality and places it in a disabled state |
floating-middleware | Middleware[] | undefined | Directly set the floating-ui middleware behavior. See above for details. |
id | string | undefined | Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed |
initial-animation | boolean | false | When set, enables the initial animation on mount |
is-nav | boolean | false | Indicates the dropdown is a nav dropdown |
lazy | boolean | false | When set, the content will not be mounted until opened |
menu-class | ClassValue | undefined | CSS class (or classes) to add to the menu container |
model-value | boolean | false | Controls the visibility of the component |
no-animation | boolean | false | When set, disables the animation |
no-caret | boolean | false | Hide the caret indicator on the toggle button |
no-fade | boolean | false | Alias for `noAnimation` |
no-flip | boolean | false | Prevent the menu from auto flipping positions |
no-shift | boolean | false | Prevent the menu from automatically shifting positions |
no-size | boolean | false | Prevent the menu from automatically resizing |
no-wrapper | boolean | false | Do not render the dropdown wrapper element |
offset | number | string | {mainAxis?: number; crossAxis?: number; alignmentAxis?: number | null | 0 | Specify the number of pixels to shift the menu by. See above for details. |
placement | Placement | 'bottom-start' | Placement of a floating element |
role | string | 'menu' | Sets the ARIA attribute `role` to a specific value |
show | boolean | false | When set, and prop 'visible' is false on mount, will animate from closed to open on initial mount. Mainly to help with template show. Use model-value for reactive show/hide |
size | Size | 'md' | Set the size of the component's appearance. 'sm', 'md' (default), or 'lg' |
split | boolean | false | When set, renders a split button dropdown |
split-button-type | ButtonType | 'button' | Value to place in the 'type' attribute on the split button: 'button', 'submit', 'reset' |
split-class | ClassValue | undefined | CSS class (or classes) to add to the split button |
split-disabled | boolean | undefined | When set, the split button is disabled |
split-href | string | undefined | Denotes the target URL of the link for the split button |
split-to | RouteLocationRaw | undefined | Denotes the target route of the split button. When clicked, the value of the to prop will be passed to router.push() internally, so the value can be either a string or a Location descriptor object |
split-variant | ButtonVariant | null | undefined | Applies one of the Bootstrap theme color variants to the split button. Defaults to the 'variant' prop value |
strategy | Strategy | 'absolute' | The strategy used to determine when to hide the dropdown. See above for details. |
teleport-disabled | boolean | false | Renders the dropdown in the exact place it was defined |
teleport-to | string | RendererElement | null | undefined | undefined | Overrides the default teleport location |
text | string | undefined | Text to place in the toggle button, or in the split button is split mode |
toggle-class | ClassValue | undefined | CSS class (or classes) to add to the toggle button |
toggle-text | string | 'Toggle dropdown' | ARIA label (visually-hidden) to set on the toggle when in split mode. Overriden by the slot of the same name |
trans-props | TransitionProps | undefined | Transition properties |
unmount-lazy | boolean | false | When set and `lazy` is true, the content will be unmounted when closed |
variant | ColorVariant | null | 'secondary' | Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence |
visible | boolean | false | When 'true', open without animation |
wrapper-class | ClassValue | undefined | CSS class (or classes) to add to the wrapper element |
Event | Args | Description |
---|---|---|
click | event : MouseEvent - Native click event object | Emitted when button is clicked |
hidden | Called after dropdown is hidden | |
hide | value : BvTriggerableEvent - Call value.preventDefault() to cancel hide | Emitted just before dropdown is hidden. Cancelable |
hide-prevented | Emitted when the dropdown tried to close, but was prevented from doing so. | |
show | value : BvTriggerableEvent - Call value.preventDefault() to cancel show | Emitted just before dropdown is shown. Cancelable |
show-prevented | Emitted when the dropdown tried to open, but was prevented from doing so. | |
shown | Called after dropdown is shown | |
split-click | event : MouseEvent - Native click event object | Emitted when split button is clicked in split mode |
toggle | Emitted when toggle button is clicked |
Name | Scope | Description |
---|---|---|
button-content | Can be used to implement custom text with icons and more styling | |
default | hide : () => void - Can be used to close the dropdownshow : () => void - Can be used to open the dropdown | Optionally scoped default slot for dropdown menu content |
toggle-text | ARIA label (visually-hidden) to set on the toggle when in split mode. Overrides the toggle-text prop |
<BNavText>
.navbar‑text
Prop | Type | Default | Description |
---|---|---|---|
text | string | undefined | Plain text to display in the nav |
Name | Scope | Description |
---|---|---|
default | Content to display in the nav |