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

<header class="c-header c-header-light px-3">
  <a class="c-header-brand" href="#">
    <img src="/images/brand/coreui-signet.svg" width="40" height="40" class="d-inline-block align-top" alt="CoreUI Logo">
    CoreUI
  </a>
  <button class="c-header-toggler" type="button">
    <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>
</header>

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.

CoreUI
Navbar
<!-- As a link -->
<header class="c-header c-header-light px-3">
  <a class="c-header-brand" href="#">CoreUI</a>
</header>

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

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 -->
<header class="c-header c-header-light px-3">
  <a class="c-header-brand" href="#">
    <img src="/images/brand/coreui-signet.svg" width="40" height="40" alt="CoreUI Logo">
  </a>
</header>
<!-- Image and text -->
<header class="c-header c-header-light px-3">
  <a class="c-header-brand" href="#">
    <img src="/images/brand/coreui-signet.svg" width="40" height="40" class="d-inline-block align-top" alt="CoreUI Logo">
    CoreUI
  </a>
</header>

Navbar navigation links build on our .c-header-nav.

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.

<header class="c-header c-header-light px-3">
  <a class="c-header-brand" href="#">CoreUI</a>
  <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>
</header>

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

<header class="c-header c-header-light px-3">
  <a class="c-header-brand" href="#">CoreUI</a>
  <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>
</header>

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.

<header class="c-header c-header-light px-3">
  <a class="c-header-brand" href="#">CoreUI</a>
  <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>
</header>

Forms

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

<header class="c-header c-header-light px-3">
  <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>
</header>

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.

Navbar
<header class="c-header c-header-light px-3">
  <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>
</header>

Input groups work, too:

@
<header class="c-header c-header-light px-3">
  <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>
</header>

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.

<header class="c-header c-header-light px-3">
  <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>
</header>

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.

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

Mix and match with other components and utilities as needed.

Navbar w/ text
<header class="c-header c-header-light px-3">
  <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>
</header>

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.

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

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

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

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">
  <header class="c-header c-header-light px-3">
    <a class="c-header-brand" href="#">CoreUI</a>
  </header>
</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.

<header class="c-header c-header-light px-3">
  <div class="container">
    <a class="c-header-brand" href="#">CoreUI</a>
  </div>
</header>

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.

<header class="c-header c-header-light px-3">
  <a class="c-header-brand" href="#">Default</a>
</header>
<header class="c-header fixed-top c-header-light px-3">
  <a class="c-header-brand" href="#">Fixed top</a>
</header>
<header class="c-header fixed-bottom c-header-light px-3">
  <a class="c-header-brand" href="#">Fixed bottom</a>
</header>
<header class="c-header c-sticky-top c-header-light px-3">
  <a class="c-header-brand" href="#">Sticky top</a>
</header>