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.

HTML
template
<BNavbar v-b-color-mode="'dark'" toggleable="lg" variant="primary">
  <BNavbarBrand href="#">NavBar</BNavbarBrand>
  <BNavbarToggle target="nav-collapse" />
  <BCollapse id="nav-collapse" is-nav>
    <BNavbarNav>
      <BNavItem href="#">Link</BNavItem>
      <BNavItem href="#" disabled>Disabled</BNavItem>
    </BNavbarNav>
    <!-- Right aligned nav items -->
    <BNavbarNav class="ms-auto mb-2 mb-lg-0">
      <BNavItemDropdown text="Lang" right>
        <BDropdownItem href="#">EN</BDropdownItem>
        <BDropdownItem href="#">ES</BDropdownItem>
        <BDropdownItem href="#">RU</BDropdownItem>
        <BDropdownItem href="#">FA</BDropdownItem>
      </BNavItemDropdown>
      <BNavItemDropdown right>
        <!-- Using 'button-content' slot -->
        <template #button-content>
          <em>User</em>
        </template>
        <BDropdownItem href="#">Profile</BDropdownItem>
        <BDropdownItem href="#">Sign Out</BDropdownItem>
      </BNavItemDropdown>
    </BNavbarNav>
    <BNavForm class="d-flex">
      <BFormInput class="me-2" placeholder="Search" />
      <BButton type="submit" variant="outline-success">Search</BButton>
    </BNavForm>
  </BCollapse>
</BNavbar>

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.

HTML
template
<BNavbar v-b-color-mode="'dark'" variant="primary">
  <BNavbarBrand tag="h1" class="mb-0">BootstrapVue</BNavbarBrand>
</BNavbar>

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:

proptypedefaultdescription
fixedExtract<Placement, 'top' | 'bottom'>undefinedSet to top for fixed to the top of the viewport, or bottom for fixed to the bottom of the viewport.
stickyExtract<Placement, 'top' | 'bottom'>undefinedSet 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 for sticky) is not fully supported in every browser. For browsers that do not support position: sticky, it will fallback natively to position: relative.

Supported content

Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:

  • BNavbarBrand for your company, product, or project name.
  • BNavbarToggle for use with the <BCollapse is-nav> component.
  • <BCollapse is-nav> for grouping and hiding navbar contents by a parent breakpoint.
  • BNavbarNav for a full-height and lightweight navigation (including support for dropdowns). The following sub-components inside BNavbarNav are supported:
    • BNavItem for link (and router-link) action items
    • BNavItemDropdown for nav dropdown menus
    • BNavText for adding vertically centered strings of text.
    • BNavForm for 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:

HTML
template
<!-- As a link -->
<BNavbar v-b-color-mode="'dark'" variant="secondary">
  <BNavbarBrand href="#">BootstrapVueNext</BNavbarBrand>
</BNavbar>
HTML
template
<!-- As a heading -->
<BNavbar v-b-color-mode="'dark'" variant="secondary">
  <BNavbarBrand tag="h1" class="mb-0">BootstrapVueNext</BNavbarBrand>
</BNavbar>

Adding images to the BNavbarBrand will likely always require custom styles or utilities to properly size. Here are some examples to demonstrate:

HTML
template
<!-- As a link -->
<BNavbar v-b-color-mode="'dark'" variant="success">
  <BNavbarBrand href="#">
    <img src="https://picsum.photos/30/30/?image=40" alt="Kitten" />
  </BNavbarBrand>
</BNavbar>
HTML
template
<!-- As a link -->
<BNavbar v-b-color-mode="'dark'" variant="success">
  <BNavbarBrand href="#">
    <img
      src="https://picsum.photos/30/30/?image=40"
      class="d-inline-block align-top"
      alt="Kitten"
    />
    BootstrapVueNext
  </BNavbarBrand>
</BNavbar>

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:

  • BNavItem for link (and router-link) action items
  • BNavText for adding vertically centered strings of text.
  • BNavItemDropdown for navbar dropdown menus
  • BNavForm for 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.

HTML
template
<BNavbar v-b-color-mode="'dark'" toggleable="sm" variant="primary">
  <BNavbarToggle target="nav-text-collapse" />
  <BNavbarBrand>BootstrapVue</BNavbarBrand>
  <BCollapse id="nav-text-collapse" is-nav>
    <BNavbarNav>
      <BNavText>Navbar text</BNavText>
    </BNavbarNav>
  </BCollapse>
</BNavbar>

BNavItemDropdown

For BNavItemDropdown usage, see the BDropdown docs. Note split dropdowns are not supported in BNavbar and BNavbarNav.

HTML
template
<BNavbar v-b-color-mode="'dark'" variant="dark">
  <BNavbarNav>
    <BNavItem href="#">Home</BNavItem>
    <BNavItemDropdown text="Lang" right>
      <BDropdownItem href="#">EN</BDropdownItem>
      <BDropdownItem href="#">ES</BDropdownItem>
      <BDropdownItem href="#">RU</BDropdownItem>
      <BDropdownItem href="#">FA</BDropdownItem>
    </BNavItemDropdown>
    <BNavItemDropdown text="User" right>
      <BDropdownItem href="#">Account</BDropdownItem>
      <BDropdownItem href="#">Settings</BDropdownItem>
    </BNavItemDropdown>
  </BNavbarNav>
</BNavbar>

BNavForm

Use BNavForm to place inline form controls into your navbar. See BNavForm docs for details.

HTML
template
<BNavbar v-b-color-mode="'dark'" variant="primary">
  <BNavForm>
    <BFormInput class="me-sm-2" placeholder="Search" />
    <BButton variant="outline-success" class="my-2 my-sm-0" type="submit">Search</BButton>
  </BNavForm>
</BNavbar>

Input Groups work as well:

HTML
template
<BNavbar v-b-color-mode="'dark'" variant="primary">
  <BNavForm>
    <BInputGroup prepend="@">
      <BFormInput placeholder="Username" />
    </BInputGroup>
  </BNavForm>
</BNavbar>

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.

HTML
vue
<template>
  <BNavbar v-b-color-mode="'dark'" toggleable variant="dark">
    <BNavbarBrand href="#">NavBar</BNavbarBrand>
    <BNavbarToggle target="navbar-toggle-collapse">
      <template #default="{expanded}">
        <ChevronBarUpIcon v-if="expanded" />
        <ChevronBarDownIcon v-else icon="chevron-bar-down" />
      </template>
    </BNavbarToggle>
    <BCollapse id="navbar-toggle-collapse" is-nav>
      <BNavbarNav class="ms-auto">
        <BNavItem href="#">Link 1</BNavItem>
        <BNavItem href="#">Link 2</BNavItem>
        <BNavItem href="#" disabled>Disabled</BNavItem>
      </BNavbarNav>
    </BCollapse>
  </BNavbar>
</template>

<script setup lang="ts">
import ChevronBarUpIcon from '~icons/bi/chevron-bar-up'
import ChevronBarDownIcon from '~icons/bi/chevron-bar-down'
</script>

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'.

HTML
vue
<template>
  <!-- #region template -->
  <BNavbar v-b-color-mode="'dark'" :toggleable="true" variant="primary">
    <BNavbarBrand href="#">NavBar</BNavbarBrand>
    <BNavbarToggle target="nav-offcanvas" />
    <BOffcanvas id="nav-offcanvas" title="Offcanvas" placement="end" is-nav>
      <BNavbarNav>
        <BNavItem href="#">Link</BNavItem>
        <BNavItem href="#" disabled>Disabled</BNavItem>
      </BNavbarNav>
      <!-- Right aligned nav items -->
      <BNavbarNav class="ms-auto mb-2 mb-lg-0">
        <BNavItemDropdown text="Lang" right>
          <BDropdownItem href="#">EN</BDropdownItem>
          <BDropdownItem href="#">ES</BDropdownItem>
          <BDropdownItem href="#">RU</BDropdownItem>
          <BDropdownItem href="#">FA</BDropdownItem>
        </BNavItemDropdown>
        <BNavItemDropdown right>
          <!-- Using 'button-content' slot -->
          <template #button-content>
            <em>User</em>
          </template>
          <BDropdownItem href="#">Profile</BDropdownItem>
          <BDropdownItem href="#">Sign Out</BDropdownItem>
        </BNavItemDropdown>
      </BNavbarNav>
      <BNavForm class="d-flex">
        <BFormInput class="me-2" placeholder="Search" />
        <BButton type="submit" variant="outline-success">Search</BButton>
      </BNavForm>
    </BOffcanvas>
  </BNavbar>
  <!-- #endregion template -->
</template>

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.

HTML
vue
<template>
  <!-- #region template -->
  <BNavbar v-b-color-mode="'dark'" :toggleable="true" variant="primary" class="navbar-nav-scroll">
    <BNavbarBrand href="#">NavBar</BNavbarBrand>
    <BNavbarToggle target="nav-scroll" />
    <BCollapse id="nav-scroll" is-nav>
      <BNavbarNav>
        <BNavItem href="#">Link</BNavItem>
        <BNavItem href="#" disabled>Disabled</BNavItem>
      </BNavbarNav>
      <!-- Right aligned nav items -->
      <BNavbarNav class="ms-auto mb-2 mb-lg-0">
        <BNavItemDropdown text="Lang" right>
          <BDropdownItem href="#">EN</BDropdownItem>
          <BDropdownItem href="#">ES</BDropdownItem>
          <BDropdownItem href="#">RU</BDropdownItem>
          <BDropdownItem href="#">FA</BDropdownItem>
        </BNavItemDropdown>
        <BNavItemDropdown right>
          <!-- Using 'button-content' slot -->
          <template #button-content>
            <em>User</em>
          </template>
          <BDropdownItem href="#">Profile</BDropdownItem>
          <BDropdownItem href="#">Sign Out</BDropdownItem>
        </BNavItemDropdown>
      </BNavbarNav>
      <BNavForm class="d-flex">
        <BFormInput class="me-2" placeholder="Search" />
        <BButton type="submit" variant="outline-success">Search</BButton>
      </BNavForm>
    </BCollapse>
  </BNavbar>
  <!-- #endregion template -->
</template>

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 component
  • false : 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 menu
  • outside : 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

  • BCollapse component
  • BSidebar component
  • v-b-toggle directive
  • BNav documentation for additional components and sub-component aliases Refer to the Router support reference page for router-link specific props.

Component Reference

<BNavbar>
PropTypeDefaultDescription
auto-closeboolean | 'inside' | 'outside'true Controls the automatic closing of the component when clicking. See above for details.
containerboolean | '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
printbooleanfalse 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
tagstring'nav' Specify the HTML tag to render instead of the default tag
toggleableboolean | Breakpointfalse 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'
variantColorVariant | nullnull Applies one of the Bootstrap theme color variants to the component. When implemented `bg-variant` and `text-variant` will take precedence
NameScopeDescription
defaultContent to place in the navbar
<BNavbarBrand>
PropTypeDefaultDescription
tagstring'ul' Specify the HTML tag to render instead of the default tag
Extensions:
NameScopeDescription
defaultContent to place in the navbar brand
<BNavbarNav>
PropTypeDefaultDescription
alignAlignmentJustifyContentundefined Align the nav items in the nav: 'start', 'end', 'center', 'between', 'around', or 'evenly'
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
smallbooleanfalse Makes the nav smaller
tagstring'ul' Specify the HTML tag to render instead of the default tag
NameScopeDescription
defaultContent to place in the navbar nav
<BNavbarToggle>
PropTypeDefaultDescription
disabledbooleanfalse When set to `true`, disables the component's functionality and places it in a disabled state
labelstring'Toggle navigation' String to place in the toggle's 'aria-label' attribute
targetstring | readonly string[]undefined ID (or array of IDs) of the collapse/sidebar components that should be toggled
EventArgsDescription
click
click: MouseEvent - Native mouse event object
Emitted when the toggle is clicked
NameScopeDescription
default
Not yet implemented: expanded: boolean - `true` if the collapse is expanded, `false` otherwise
Alternate content to replace the default Bootstrap hamburger