core-logo

Bootstrap navbar

Documentation and examples for Bootstrap's powerful, responsive navigation header, the navbar. Includes support for branding, navigation, and more, including support for our collapse plugin.

On this page:



How it works

Here’s what you need to know before getting started with the navbar:

  • Navbars require a wrapping .c-navbar with .c-navbar-expand{-sm|-md|-lg|-xl} for responsive collapsing and color scheme classes.
  • Navbars and their contents are fluid by default. Use optional containers to limit their horizontal width.
  • Use our spacing and flex utility classes for controlling spacing and alignment within navbars.
  • Navbars are responsive by default, but you can easily modify them to change that. Responsive behavior depends on our Collapse JavaScript plugin.
  • Navbars are hidden by default when printing. Force them to be printed by adding .c-d-print to the .c-navbar. See the display utility class.
  • Ensure accessibility by using a <nav> element or, if using a more generic element such as a <div>, add a role="navigation" to every navbar to explicitly identify it as a landmark region for users of assistive technologies.
The animation effect of this component is dependent on the prefers-reduced-motion media query. See the reduced motion section of our accessibility documentation.

Read on for an example and list of supported sub-components.

Supported content

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

  • .c-navbar-brand for your company, product, or project name.
  • .c-navbar-nav for a full-height and lightweight navigation (including support for dropdowns).
  • .c-navbar-toggler for use with our collapse plugin and other navigation toggling behaviors.
  • .c-form-inline for any form controls and actions.
  • .c-navbar-text for adding vertically centered strings of text.
  • .c-collapse.c-navbar-collapse for grouping and hiding navbar contents by a parent breakpoint.

Here’s an example of all the sub-components included in a responsive light-themed navbar that automatically collapses at the lg (large) breakpoint.

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Navbar</a>
  <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-navbar-toggler-icon"></span>
  </button>

  <div class="c-collapse c-navbar-collapse" id="navbarSupportedContent">
    <ul class="c-navbar-nav c-mr-auto">
      <li class="c-nav-item active">
        <a class="c-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Link</a>
      </li>
      <li class="c-nav-item c-dropdown">
        <a class="c-nav-link c-dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="c-dropdown" aria-expanded="false">
          Dropdown
        </a>
        <div class="c-dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="c-dropdown-item" href="#">Action</a>
          <a class="c-dropdown-item" href="#">Another action</a>
          <div class="c-dropdown-divider"></div>
          <a class="c-dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
    <form class="c-form-inline c-my-2 c-my-lg-0">
      <input class="c-form-control c-mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="c-btn c-btn-outline-success c-my-2 c-my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

This example uses color (bg-light) and spacing (my-2, my-lg-0, mr-sm-0, my-sm-0) utility classes.

Brand

The .c-navbar-brand can be applied to most elements, but an anchor works best as some elements might require utility classes or custom styles.

<!-- As a link -->
<nav class="c-navbar c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Navbar</a>
</nav>

<!-- As a heading -->
<nav class="c-navbar c-navbar-light c-bg-light">
  <span class="c-navbar-brand c-mb-0 c-h1">Navbar</span>
</nav>

Adding images to the .c-navbar-brand will likely always require custom styles or utilities to properly size. Here are some examples to demonstrate.

<!-- Just an image -->
<nav class="c-navbar c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">
    <img src="/docs/3.0.0-alpha.13/assets/brand/bootstrap-solid.svg" width="30" height="30" alt="">
  </a>
</nav>
<!-- Image and text -->
<nav class="c-navbar c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">
    <img src="/docs/3.0.0-alpha.13/assets/brand/bootstrap-solid.svg" width="30" height="30" class="c-d-inline-block c-align-top" alt="">
    Bootstrap
  </a>
</nav>

Navbar navigation links build on our .c-nav options with their own modifier class and require the use of toggler classes 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.

Active states—with .active—to indicate the current page can be applied directly to .c-nav-links or their immediate parent .c-nav-items.

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Navbar</a>
  <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-navbar-toggler-icon"></span>
  </button>
  <div class="c-collapse c-navbar-collapse" id="navbarNav">
    <ul class="c-navbar-nav">
      <li class="c-nav-item active">
        <a class="c-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Features</a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Pricing</a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
  </div>
</nav>

And because we use classes for our navs, you can avoid the list-based approach entirely if you like.

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Navbar</a>
  <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-navbar-toggler-icon"></span>
  </button>
  <div class="c-collapse c-navbar-collapse" id="navbarNavAltMarkup">
    <div class="c-navbar-nav">
      <a class="c-nav-item c-nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="c-nav-item c-nav-link" href="#">Features</a>
      <a class="c-nav-item c-nav-link" href="#">Pricing</a>
      <a class="c-nav-item c-nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
    </div>
  </div>
</nav>

You may also utilize dropdowns in your navbar nav. Dropdown menus require a wrapping element for positioning, so be sure to use separate and nested elements for .c-nav-item and .c-nav-link as shown below.

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Navbar</a>
  <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-navbar-toggler-icon"></span>
  </button>
  <div class="c-collapse c-navbar-collapse" id="navbarNavDropdown">
    <ul class="c-navbar-nav">
      <li class="c-nav-item active">
        <a class="c-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Features</a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Pricing</a>
      </li>
      <li class="c-nav-item c-dropdown">
        <a class="c-nav-link c-dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button" data-toggle="c-dropdown" aria-expanded="false">
          Dropdown link
        </a>
        <div class="c-dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
          <a class="c-dropdown-item" href="#">Action</a>
          <a class="c-dropdown-item" href="#">Another action</a>
          <a class="c-dropdown-item" href="#">Something else here</a>
        </div>
      </li>
    </ul>
  </div>
</nav>

Forms

Place various form controls and components within a navbar with .c-form-inline.

<nav class="c-navbar c-navbar-light c-bg-light">
  <form class="c-form-inline">
    <input class="c-form-control c-mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="c-btn c-btn-outline-success c-my-2 c-my-sm-0" type="submit">Search</button>
  </form>
</nav>

Immediate children elements in .c-navbar use flex layout and will default to justify-content: between. Use additional flex utilities as needed to adjust this behavior.

<nav class="c-navbar c-navbar-light c-bg-light">
  <a class="c-navbar-brand">Navbar</a>
  <form class="c-form-inline">
    <input class="c-form-control c-mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="c-btn c-btn-outline-success c-my-2 c-my-sm-0" type="submit">Search</button>
  </form>
</nav>

Input groups work, too:

<nav class="c-navbar c-navbar-light c-bg-light">
  <form class="c-form-inline">
    <div class="c-input-group">
      <div class="c-input-group-prepend">
        <span class="c-input-group-text" id="basic-addon1">@</span>
      </div>
      <input type="text" class="c-form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
    </div>
  </form>
</nav>

Various buttons are supported as part of these navbar forms, too. This is also a great reminder that vertical alignment utilities can be used to align different sized elements.

<nav class="c-navbar c-navbar-light c-bg-light">
  <form class="c-form-inline">
    <button class="c-btn c-btn-outline-success" type="button">Main button</button>
    <button class="c-btn c-btn-sm c-btn-outline-secondary" type="button">Smaller button</button>
  </form>
</nav>

Text

Navbars may contain bits of text with the help of .c-navbar-text. This class adjusts vertical alignment and horizontal spacing for strings of text.

<nav class="c-navbar c-navbar-light c-bg-light">
  <span class="c-navbar-text">
    Navbar text with an inline element
  </span>
</nav>

Mix and match with other components and utilities as needed.

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Navbar w/ text</a>
  <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-navbar-toggler-icon"></span>
  </button>
  <div class="c-collapse c-navbar-collapse" id="navbarText">
    <ul class="c-navbar-nav c-mr-auto">
      <li class="c-nav-item active">
        <a class="c-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Features</a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Pricing</a>
      </li>
    </ul>
    <span class="c-navbar-text">
      Navbar text with an inline element
    </span>
  </div>
</nav>

Color schemes

Theming the navbar has never been easier thanks to the combination of theming classes and background-color utilities. Choose from .c-navbar-light for use with light background colors, or .c-navbar-dark for dark background colors. Then, customize with .c-bg-* utilities.

<nav class="c-navbar c-navbar-dark c-bg-dark">
  <!-- Navbar content -->
</nav>

<nav class="c-navbar c-navbar-dark c-bg-primary">
  <!-- Navbar content -->
</nav>

<nav class="c-navbar c-navbar-light" style="background-color: #e3f2fd;">
  <!-- Navbar content -->
</nav>

Containers

Although it’s not required, you can wrap a navbar in a .c-container to center it on a page or add one within to only center the contents of a fixed or static top navbar.

<div class="c-container">
  <nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
    <a class="c-navbar-brand" href="#">Navbar</a>
  </nav>
</div>

When the container is within your navbar, its horizontal padding is removed at breakpoints lower than your specified .c-navbar-expand{-sm|-md|-lg|-xl} class. This ensures we’re not doubling up on padding unnecessarily on lower viewports when your navbar is collapsed.

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <div class="c-container">
    <a class="c-navbar-brand" href="#">Navbar</a>
  </div>
</nav>

Placement

Use our 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 .c-sticky-top uses position: sticky, which isn’t fully supported in every browser.

<nav class="c-navbar c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Default</a>
</nav>
<nav class="c-navbar c-fixed-top c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Fixed top</a>
</nav>
<nav class="c-navbar c-fixed-bottom c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Fixed bottom</a>
</nav>
<nav class="c-navbar c-sticky-top c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Sticky top</a>
</nav>

Responsive behaviors

Navbars can utilize .c-navbar-toggler, .c-navbar-collapse, and .c-navbar-expand{-sm|-md|-lg|-xl} classes to change when their content collapses behind a button. In combination with other utilities, you can easily choose when to show or hide particular elements.

For navbars that never collapse, add the .c-navbar-expand class on the navbar. For navbars that always collapse, don’t add any .c-navbar-expand class.

Toggler

Navbar togglers are left-aligned by default, but should they follow a sibling element like a .c-navbar-brand, they’ll automatically be aligned to the far right. Reversing your markup will reverse the placement of the toggler. Below are examples of different toggle styles.

With no .c-navbar-brand shown in lowest breakpoint:

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-navbar-toggler-icon"></span>
  </button>
  <div class="c-collapse c-navbar-collapse" id="navbarTogglerDemo01">
    <a class="c-navbar-brand" href="#">Hidden brand</a>
    <ul class="c-navbar-nav c-mr-auto c-mt-2 c-mt-lg-0">
      <li class="c-nav-item active">
        <a class="c-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Link</a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
    <form class="c-form-inline c-my-2 c-my-lg-0">
      <input class="c-form-control c-mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="c-btn c-btn-outline-success c-my-2 c-my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

With a brand name shown on the left and toggler on the right:

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <a class="c-navbar-brand" href="#">Navbar</a>
  <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-navbar-toggler-icon"></span>
  </button>

  <div class="c-collapse c-navbar-collapse" id="navbarTogglerDemo02">
    <ul class="c-navbar-nav c-mr-auto c-mt-2 c-mt-lg-0">
      <li class="c-nav-item active">
        <a class="c-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Link</a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
    <form class="c-form-inline c-my-2 c-my-lg-0">
      <input class="c-form-control c-mr-sm-2" type="search" placeholder="Search">
      <button class="c-btn c-btn-outline-success c-my-2 c-my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

With a toggler on the left and brand name on the right:

<nav class="c-navbar c-navbar-expand-lg c-navbar-light c-bg-light">
  <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-navbar-toggler-icon"></span>
  </button>
  <a class="c-navbar-brand" href="#">Navbar</a>

  <div class="c-collapse c-navbar-collapse" id="navbarTogglerDemo03">
    <ul class="c-navbar-nav c-mr-auto c-mt-2 c-mt-lg-0">
      <li class="c-nav-item active">
        <a class="c-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link" href="#">Link</a>
      </li>
      <li class="c-nav-item">
        <a class="c-nav-link disabled" href="#" tabindex="-1" aria-disabled="true">Disabled</a>
      </li>
    </ul>
    <form class="c-form-inline c-my-2 c-my-lg-0">
      <input class="c-form-control c-mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="c-btn c-btn-outline-success c-my-2 c-my-sm-0" type="submit">Search</button>
    </form>
  </div>
</nav>

External content

Sometimes you want to use the collapse plugin to trigger hidden content elsewhere on the page. Because our plugin works on the id and data-target matching, that’s easily done!

<div class="pos-f-t">
  <div class="c-collapse" id="navbarToggleExternalContent">
    <div class="c-bg-dark c-p-4">
      <h5 class="c-text-white c-h4">Collapsed content</h5>
      <span class="c-text-muted">Toggleable via the navbar brand.</span>
    </div>
  </div>
  <nav class="c-navbar c-navbar-dark c-bg-dark">
    <button class="c-navbar-toggler" type="button" data-toggle="c-collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="c-navbar-toggler-icon"></span>
    </button>
  </nav>
</div>