core-logo

Header

Documentation and examples for CoreUI's powerful, responsive header. Includes support for branding, navigation, and more.

On this page:



How it works

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

  • Header requires a wrapping .c-headerand 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 to the .c-header. 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-header-brand for your company, product, or project name.
  • .c-header-nav for a full-height and lightweight navigation (including support for dropdowns).
  • .c-header-toggler for use with our collapse plugin and other navigation toggling behaviors.
  • .c-header-text for adding vertically centered strings of text.

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-header c-header-light">
  <a class="c-header-brand" href="#">CoreUI</a>
  <button class="c-header-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-header-toggler-icon"></span>
  </button>

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

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

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

<!-- Just an image -->
<nav class="c-header c-header-light">
  <a class="c-header-brand" href="#">
    <img src="/docs/3.0-beta/assets/brand/coreui-signet.svg" width="30" height="30" alt="CoreUI Logo">
  </a>
</nav>
<!-- Image and text -->
<nav class="c-header c-header-light">
  <a class="c-header-brand" href="#">
    <img src="/docs/3.0-beta/assets/brand/coreui-signet.svg" width="30" height="30" class="d-inline-block align-top" alt="CoreUI Logo">
    CoreUI
  </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-header-nav-links or their immediate parent .c-header-nav-items.

<nav class="c-header c-header-light">
  <a class="c-header-brand" href="#">CoreUI</a>
  <button class="c-header-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-header-toggler-icon"></span>
  </button>
  <div class="collapse c-header-collapse" id="navbarNav">
    <ul class="c-header-nav">
      <li class="c-header-nav-item active">
        <a class="c-header-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-header-nav-item">
        <a class="c-header-nav-link" href="#">Features</a>
      </li>
      <li class="c-header-nav-item">
        <a class="c-header-nav-link" href="#">Pricing</a>
      </li>
      <li class="c-header-nav-item">
        <a class="c-header-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-header c-header-light">
  <a class="c-header-brand" href="#">CoreUI</a>
  <button class="c-header-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-header-toggler-icon"></span>
  </button>
  <div class="collapse c-header-collapse" id="navbarNavAltMarkup">
    <div class="c-header-nav">
      <a class="c-header-nav-item c-header-nav-link active" href="#">Home <span class="sr-only">(current)</span></a>
      <a class="c-header-nav-item c-header-nav-link" href="#">Features</a>
      <a class="c-header-nav-item c-header-nav-link" href="#">Pricing</a>
      <a class="c-header-nav-item c-header-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-header-nav-item and .c-header-nav-link as shown below.

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

Forms

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

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

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

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

Input groups work, too:

<nav class="c-header c-header-light">
  <form class="form-inline">
    <div class="input-group">
      <div class="input-group-prepend">
        <span class="input-group-text" id="basic-addon1">@</span>
      </div>
      <input type="text" class="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-header c-header-light">
  <form class="form-inline">
    <button class="btn btn-outline-success" type="button">Main button</button>
    <button class="btn btn-sm btn-outline-secondary" type="button">Smaller button</button>
  </form>
</nav>

Text

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

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

Mix and match with other components and utilities as needed.

<nav class="c-header c-header-light">
  <a class="c-header-brand" href="#">Navbar w/ text</a>
  <button class="c-header-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
    <span class="c-header-toggler-icon"></span>
  </button>
  <div class="collapse c-header-collapse" id="navbarText">
    <ul class="c-header-nav mr-auto">
      <li class="c-header-nav-item active">
        <a class="c-header-nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="c-header-nav-item">
        <a class="c-header-nav-link" href="#">Features</a>
      </li>
      <li class="c-header-nav-item">
        <a class="c-header-nav-link" href="#">Pricing</a>
      </li>
    </ul>
    <span class="c-header-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-header-light for use with light background colors, or .c-header-dark for dark background colors. Then, customize with .bg-* utilities.

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

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

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

Containers

Although it’s not required, you can wrap a navbar in a .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="container">
  <nav class="c-header c-header-light">
    <a class="c-header-brand" href="#">CoreUI</a>
  </nav>
</div>

When the container is within your navbar, its horizontal padding is removed at breakpoints lower than your specified .c-header-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-header c-header-light">
  <div class="container">
    <a class="c-header-brand" href="#">CoreUI</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-header c-header-light">
  <a class="c-header-brand" href="#">Default</a>
</nav>
<nav class="c-header fixed-top c-header-light">
  <a class="c-header-brand" href="#">Fixed top</a>
</nav>
<nav class="c-header fixed-bottom c-header-light">
  <a class="c-header-brand" href="#">Fixed bottom</a>
</nav>
<nav class="c-header c-sticky-top c-header-light">
  <a class="c-header-brand" href="#">Sticky top</a>
</nav>