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.

HTML
template
<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

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.

HTML
template
<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.

HTML
template
<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.

HTML
template
<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.

HTML
template
<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.

HTML
template
<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.

HTML
template
<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.

HTML
template
<BNav vertical class="w-25">
  <BNavItem active>Active</BNavItem>
  <BNavItem>Link</BNavItem>
  <BNavItem>Another Link</BNavItem>
  <BNavItem disabled>Disabled</BNavItem>
</BNav>

Use <BNavItemDropdown> to place dropdown items within your nav.

HTML
template
<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:

html
<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 MethodDescription
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.

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.

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.

<BNavItemDropdown> exposes the same methods as <BDropdown>, see the dropdown documentation for details.

Use the <BNavText> child component to place plain text content into the nav:

HTML
template
<BNav>
  <BNavItem href="#1">Link 1</BNavItem>
  <BNavItem href="#2">Link 2</BNavItem>
  <BNavText>Plain text</BNavText>
</BNav>

Use the <BNavForm> child component to place an inline form into the nav:

HTML
vue
<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.

HTML
template
<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.

HTML
template
<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.

HTML
template
<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:

template
<!-- 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:

js
/* 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

PropTypeDefaultDescription
alignAlignmentJustifyContentundefined Align the nav items in the nav to any value of AlignmentJustifyContent
card-headerbooleanfalse Set this prop when the nav is placed inside a card header
fillbooleanfalse Proportionately fills all horizontal space with nav items. All horizontal space is occupied, but not every nav item has the same width
justifiedbooleanfalse Fills all horizontal space with nav items, but unlike 'fill', every nav item will be the same width
pillsbooleanfalse Renders the nav items with the appearance of pill buttons
smallbooleanfalse Makes the nav smaller
tabsbooleanfalse Renders the nav items with the appearance of tabs
tagstring'ul' Specify the HTML tag to render instead of the default tag
underlinebooleanfalse Adds an underline to the active nav item
verticalbooleanfalse Stacks the nav items vertically
NameScopeDescription
defaultContent to place in the nav
<BNavForm>
PropTypeDefaultDescription
floatingbooleanfalse 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-classClassValueundefined CSS class (or classes) to add to the form element
idstringundefined Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed
novalidatebooleanfalse When set, disables browser native HTML5 validation on controls in the form
rolestringundefined Sets the ARIA attribute `role` to a specific value
validatedbooleanfalse When set, adds the Bootstrap class 'was-validated' on the form, triggering the native browser validation states
wrapper-attrsReadonly<AttrsValue>undefined Attributes to be applied to the wrapper element
EventArgsDescription
submit
submit: Event - Native submit event
Emitted when the form is submitted
NameScopeDescription
defaultContent to place in the nav form
<BNavItem>
PropTypeDefaultDescription
link-attrsReadonly<AttrsValue>undefined Additional attributes to place on the nested link element
link-classClassValueundefined CSS class (or classes) to place on the nested link element
Extensions:
EventArgsDescription
click
click: MouseEvent - On click event
Emitted when non-disabled nav item clicked
NameScopeDescription
defaultContent to place in the nav item
<BNavItemDropdown>
PropTypeDefaultDescription
aria-labelstringundefined Sets the value of `aria-label` attribute on the rendered element
auto-closeboolean | 'inside' | 'outside'true Controls the automatic closing of the dropdown when clicking. See above for details.
boundaryBoundary | RootBoundary'clippingAncestors' The boundary constraint of dropdown: any value of floating-us's Boundary or RootBoundary type. See above for details.
boundary-paddingPaddingundefined The virtual padding around the boundary to check for overflow
disabledbooleanfalse When set to `true`, disables the component's functionality and places it in a disabled state
floating-middlewareMiddleware[]undefined Directly set the floating-ui middleware behavior. See above for details.
idstringundefined Used to set the `id` attribute on the rendered content, and used as the base to generate any additional element IDs as needed
initial-animationbooleanfalse When set, enables the initial animation on mount
is-navbooleanfalse Indicates the dropdown is a nav dropdown
lazybooleanfalse When set, the content will not be mounted until opened
menu-classClassValueundefined CSS class (or classes) to add to the menu container
model-valuebooleanfalse Controls the visibility of the component
no-animationbooleanfalse When set, disables the animation
no-caretbooleanfalse Hide the caret indicator on the toggle button
no-fadebooleanfalse Alias for `noAnimation`
no-flipbooleanfalse Prevent the menu from auto flipping positions
no-shiftbooleanfalse Prevent the menu from automatically shifting positions
no-sizebooleanfalse Prevent the menu from automatically resizing
no-wrapperbooleanfalse Do not render the dropdown wrapper element
offsetnumber | string | {mainAxis?: number; crossAxis?: number; alignmentAxis?: number | null0 Specify the number of pixels to shift the menu by. See above for details.
placementPlacement'bottom-start' Placement of a floating element
rolestring'menu' Sets the ARIA attribute `role` to a specific value
showbooleanfalse 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
sizeSize'md' Set the size of the component's appearance. 'sm', 'md' (default), or 'lg'
splitbooleanfalse When set, renders a split button dropdown
split-button-typeButtonType'button' Value to place in the 'type' attribute on the split button: 'button', 'submit', 'reset'
split-classClassValueundefined CSS class (or classes) to add to the split button
split-disabledbooleanundefined When set, the split button is disabled
split-hrefstringundefined Denotes the target URL of the link for the split button
split-toRouteLocationRawundefined 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-variantButtonVariant | nullundefined Applies one of the Bootstrap theme color variants to the split button. Defaults to the 'variant' prop value
strategyStrategy'absolute' The strategy used to determine when to hide the dropdown. See above for details.
teleport-disabledbooleanfalse Renders the dropdown in the exact place it was defined
teleport-tostring | RendererElement | null | undefinedundefined Overrides the default teleport location
textstringundefined Text to place in the toggle button, or in the split button is split mode
toggle-classClassValueundefined CSS class (or classes) to add to the toggle button
toggle-textstring'Toggle dropdown' ARIA label (visually-hidden) to set on the toggle when in split mode. Overriden by the slot of the same name
trans-propsTransitionPropsundefined Transition properties
unmount-lazybooleanfalse When set and `lazy` is true, the content will be unmounted when closed
variantColorVariant | null'secondary' Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence
visiblebooleanfalse When 'true', open without animation
wrapper-classClassValueundefined CSS class (or classes) to add to the wrapper element
EventArgsDescription
click
event: MouseEvent - Native click event object
Emitted when button is clicked
hiddenCalled after dropdown is hidden
hide
value: BvTriggerableEvent - Call value.preventDefault() to cancel hide
Emitted just before dropdown is hidden. Cancelable
hide-preventedEmitted 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-preventedEmitted when the dropdown tried to open, but was prevented from doing so.
shownCalled after dropdown is shown
split-click
event: MouseEvent - Native click event object
Emitted when split button is clicked in split mode
toggleEmitted when toggle button is clicked
NameScopeDescription
button-contentCan be used to implement custom text with icons and more styling
default
hide: () => void - Can be used to close the dropdown
show: () => void - Can be used to open the dropdown
Optionally scoped default slot for dropdown menu content
toggle-textARIA label (visually-hidden) to set on the toggle when in split mode. Overrides the toggle-text prop
<BNavText>
PropTypeDefaultDescription
textstringundefined Plain text to display in the nav
NameScopeDescription
defaultContent to display in the nav