Navbar

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

How it works

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

  • Navbars require a wrapping .navbar_sth with .navbar-expand{-sm|-md|-lg|-xl}_sth 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 .d-print_sth to the .navbar_sth. 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.

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:

  • .navbar-brand_sth for your company, product, or project name.
  • .navbar-nav_sth for a full-height and lightweight navigation (including support for dropdowns).
  • .navbar-toggler_sth for use with our collapse plugin and other navigation toggling behaviors.
  • .form-inline_sth for any form controls and actions.
  • .navbar-text_sth for adding vertically centered strings of text.
  • .collapse.navbar-collapse_sth 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="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Navbar</a>
  <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon_sth"></span>
  </button>

  <div class="collapse_sth navbar-collapse_sth" id="navbarSupportedContent">
    <ul class="navbar-nav_sth mr-auto_sth">
      <li class="nav-item_sth active_sth">
        <a class="nav-link_sth" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Link</a>
      </li>
      <li class="nav-item_sth dropdown_sth">
        <a class="nav-link_sth dropdown-toggle_sth" href="#" id="navbarDropdown" role="button" data-toggle_sth="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu_sth" aria-labelledby="navbarDropdown">
          <a class="dropdown-item_sth" href="#">Action</a>
          <a class="dropdown-item_sth" href="#">Another action</a>
          <div class="dropdown-divider_sth"></div>
          <a class="dropdown-item_sth" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth disabled_sth" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline_sth my-2_sth my-lg-0_sth">
      <input class="form-control_sth mr-sm-2_sth" type="search" placeholder="Search" aria-label="Search">
      <button class="btn_sth btn-outline-success_sth my-2_sth my-sm-0_sth" 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 .navbar-brand_sth 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="navbar_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Navbar</a>
</nav>

<!-- As a heading -->
<nav class="navbar_sth navbar-light_sth bg-light_sth">
  <span class="navbar-brand_sth mb-0_sth h1_sth">Navbar</span>
</nav>

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

<!-- Just an image -->
<nav class="navbar_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">
    <img src="/assets/brand/bootstrap-solid.svg" width="30" height="30" alt="">
  </a>
</nav>
<!-- Image and text -->
<nav class="navbar_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">
    <img src="/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block_sth align-top_sth" alt="">
    InPage
  </a>
</nav>

Navbar navigation links build on our .nav_sth 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_sth—to indicate the current page can be applied directly to .nav-link_sths or their immediate parent .nav-item_sths.

<nav class="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Navbar</a>
  <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon_sth"></span>
  </button>
  <div class="collapse_sth navbar-collapse_sth" id="navbarNav">
    <ul class="navbar-nav_sth">
      <li class="nav-item_sth active_sth">
        <a class="nav-link_sth" href="#">Home <span class="sr-only_sth">(current)</span></a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Features</a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Pricing</a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth disabled_sth" href="#">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="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Navbar</a>
  <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon_sth"></span>
  </button>
  <div class="collapse_sth navbar-collapse_sth" id="navbarNavAltMarkup">
    <div class="navbar-nav_sth">
      <a class="nav-item_sth nav-link_sth active_sth" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="nav-item_sth nav-link_sth" href="#">Features</a>
      <a class="nav-item_sth nav-link_sth" href="#">Pricing</a>
      <a class="nav-item_sth nav-link_sth disabled_sth" href="#">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 .nav-item_sth and .nav-link_sth as shown below.

<nav class="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Navbar</a>
  <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon_sth"></span>
  </button>
  <div class="collapse_sth navbar-collapse_sth" id="navbarNavDropdown">
    <ul class="navbar-nav_sth">
      <li class="nav-item_sth active_sth">
        <a class="nav-link_sth" href="#">Home <span class="sr-only_sth">(current)</span></a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Features</a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Pricing</a>
      </li>
      <li class="nav-item_sth dropdown_sth">
        <a class="nav-link_sth dropdown-toggle_sth" href="#" id="navbarDropdownMenuLink" data-toggle_sth="dropdown" aria-haspopup="true" aria-expanded="false">
          Dropdown link
        </a>
        <div class="dropdown-menu_sth" aria-labelledby="navbarDropdownMenuLink">
          <a class="dropdown-item_sth" href="#">Action</a>
          <a class="dropdown-item_sth" href="#">Another action</a>
          <a class="dropdown-item_sth" href="#">Something else here</a>
        </div>
      </li>
    </ul>
  </div>
</nav>

Forms

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

<nav class="navbar_sth navbar-light_sth bg-light_sth">
  <form class="form-inline_sth">
    <input class="form-control_sth mr-sm-2_sth" type="search" placeholder="Search" aria-label="Search">
    <button class="btn_sth btn-outline-success_sth my-2_sth my-sm-0_sth" type="submit">Search</button>
  </form>
</nav>

Align the contents of your inline forms with utilities as needed.

<nav class="navbar_sth navbar-light_sth bg-light_sth justify-content-between_sth">
  <a class="navbar-brand_sth">Navbar</a>
  <form class="form-inline_sth">
    <input class="form-control_sth mr-sm-2_sth" type="search" placeholder="Search" aria-label="Search">
    <button class="btn_sth btn-outline-success_sth my-2_sth my-sm-0_sth" type="submit">Search</button>
  </form>
</nav>

Input groups work, too:

<nav class="navbar_sth navbar-light_sth bg-light_sth">
  <form class="form-inline_sth">
    <div class="input-group_sth">
      <span class="input-group-addon_sth" id="basic-addon1">@</span>
      <input type="text" class="form-control_sth" 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="navbar_sth navbar-light_sth bg-light_sth">
  <form class="form-inline_sth">
    <button class="btn_sth btn-outline-success_sth" type="button">Main button</button>
    <button class="btn_sth btn-sm align-middle_sth btn-outline-secondary_sth" type="button">Smaller button</button>
  </form>
</nav>

Text

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

<nav class="navbar_sth navbar-light_sth bg-light_sth">
  <span class="navbar-text_sth">
    Navbar text with an inline element
  </span>
</nav>

Mix and match with other components and utilities as needed.

<nav class="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Navbar w/ text</a>
  <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon_sth"></span>
  </button>
  <div class="collapse_sth navbar-collapse_sth" id="navbarText">
    <ul class="navbar-nav_sth mr-auto_sth">
      <li class="nav-item_sth active_sth">
        <a class="nav-link_sth" href="#">Home <span class="sr-only_sth">(current)</span></a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Features</a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Pricing</a>
      </li>
    </ul>
    <span class="navbar-text_sth">
      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 .navbar-light_sth for use with light background colors, or .navbar-dark_sth for dark background colors. Then, customize with .bg-*_sth utilities.

<nav class="navbar_sth navbar-dark_sth bg-dark_sth">
  <!-- Navbar content -->
</nav>

<nav class="navbar_sth navbar-dark_sth bg-primary_sth">
  <!-- Navbar content -->
</nav>

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

Containers

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

<div class="container_sth">
  <nav class="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
    <a class="navbar-brand_sth_sth" href="#">Navbar</a>
  </nav>
</div>

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

<nav class="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <div class="container_sth">
    <a class="navbar-brand_sth" 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 .sticky-top_sth uses position: sticky, which isn’t fully supported in every browser.

<nav class="navbar_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Default</a>
</nav>
<nav class="navbar_sth fixed-top_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Fixed top</a>
</nav>
<nav class="navbar_sth fixed-bottom_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Fixed bottom</a>
</nav>
<nav class="navbar_sth sticky-top navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Sticky top</a>
</nav>

Responsive behaviors

Navbars can utilize .navbar-toggler_sth, .navbar-collapse_sth, and .navbar-expand{-sm|-md|-lg|-xl}_sth 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 .navbar-expand_sth class on the navbar. For navbars that always collapse, don’t add any .navbar-expand_sth class.

Toggler

Navbar togglers are left-aligned by default, but should they follow a sibling element like a .navbar-brand_sth, 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 .navbar-brand_sth shown in lowest breakpoint:

<nav class="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon_sth"></span>
  </button>
  <div class="collapse_sth navbar-collapse_sth" id="navbarTogglerDemo01">
    <a class="navbar-brand_sth" href="#">Hidden brand</a>
    <ul class="navbar-nav_sth mr-auto_sth mt-2_sth mt-lg-0_sth">
      <li class="nav-item_sth active_sth">
        <a class="nav-link_sth" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Link</a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth disabled_sth" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline_sth my-2_sth my-lg-0_sth">
      <input class="form-control_sth mr-sm-2_sth" type="search" placeholder="Search" aria-label="Search">
      <button class="btn_sth btn-outline-success_sth my-2_sth my-sm-0_sth" type="submit">Search</button>
    </form>
  </div>
</nav>

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

<nav class="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <a class="navbar-brand_sth" href="#">Navbar</a>
  <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarTogglerDemo02" aria-controls="navbarTogglerDemo02" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon_sth"></span>
  </button>

  <div class="collapse_sth navbar-collapse_sth" id="navbarTogglerDemo02">
    <ul class="navbar-nav_sth mr-auto_sth mt-2_sth mt-lg-0_sth">
      <li class="nav-item_sth active_sth">
        <a class="nav-link_sth" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Link</a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth disabled_sth" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline_sth my-2_sth my-lg-0_sth">
      <input class="form-control_sth mr-sm-2_sth" type="search" placeholder="Search">
      <button class="btn_sth btn-outline-success_sth my-2_sth my-sm-0_sth" type="submit">Search</button>
    </form>
  </div>
</nav>

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

<nav class="navbar_sth navbar-expand-lg_sth navbar-light_sth bg-light_sth">
  <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarTogglerDemo03" aria-controls="navbarTogglerDemo03" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon_sth"></span>
  </button>
  <a class="navbar-brand_sth" href="#">Navbar</a>

  <div class="collapse_sth navbar-collapse_sth" id="navbarTogglerDemo03">
    <ul class="navbar-nav_sth mr-auto_sth mt-2_sth mt-lg-0_sth">
      <li class="nav-item_sth active_sth">
        <a class="nav-link_sth" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth" href="#">Link</a>
      </li>
      <li class="nav-item_sth">
        <a class="nav-link_sth disabled_sth" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline_sth my-2_sth my-lg-0_sth">
      <input class="form-control_sth mr-sm-2_sth" type="search" placeholder="Search" aria-label="Search">
      <button class="btn_sth btn-outline-success_sth my-2_sth my-sm-0_sth" 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_sth matching, that’s easily done!

<div class="pos-f-t_sth">
  <div class="collapse_sth" id="navbarToggleExternalContent">
    <div class="bg-dark_sth p-4_sth">
      <h4 class="text-white_sth">Collapsed content</h4>
      <span class="text-muted_sth">Toggleable via the navbar brand.</span>
    </div>
  </div>
  <nav class="navbar_sth navbar-dark_sth bg-dark_sth">
    <button class="navbar-toggler_sth" type="button" data-toggle_sth="collapse" data-target_sth="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon_sth"></span>
    </button>
  </nav>
</div>