2014-07-14 08:33:54 +02:00
---
2015-08-15 07:45:55 +02:00
layout: docs
2014-10-27 12:52:48 +01:00
title: Navbar
2016-10-03 03:19:47 +02:00
description: Documentation and examples for Bootstrap's powerful, responsive navigation header.
2015-08-06 02:47:45 +02:00
group: components
2014-07-14 08:33:54 +02:00
---
2016-12-21 22:08:34 +01:00
The navbar is a wrapper that positions branding, navigation, and other elements in a concise header. It's easily extensible and, thanks to our Collapse plugin, can easily integrate responsive behaviors.
2014-07-14 08:33:54 +02:00
2015-05-29 10:58:52 +02:00
## Contents
* Will be replaced with the ToC, excluding the "Contents" header
{:toc}
2016-12-21 22:12:55 +01:00
## How it works
2014-10-27 12:49:24 +01:00
Here's what you need to know before getting started with the navbar:
2016-12-21 22:08:34 +01:00
- Navbars require a wrapping `.navbar` and [color scheme ](#color-schemes ) classes.
2014-10-27 12:49:24 +01:00
- Navbars and their contents are fluid by default. Use [optional containers ](#containers ) to limit their horizontal width.
2016-12-21 22:12:55 +01:00
- Navbars and their contents are built with flexbox, providing easy alignment options via utility classes.
- Navbars are responsive by default, but you can easily modify them to change that. Responsive behavior depends on our Collapse JavaScript plugin.
2014-12-01 05:17:45 +01:00
- 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.
2014-10-27 12:49:24 +01:00
2016-12-21 22:12:55 +01:00
Read on for an example and list of supported sub-components.
2015-08-18 08:43:59 +02:00
## Supported content
2014-10-27 12:49:24 +01:00
2016-12-21 22:08:34 +01:00
Navbars come with built-in support for a handful of sub-components. Choose from the following as needed:
2014-10-27 12:49:24 +01:00
2015-08-18 08:43:59 +02:00
- `.navbar-brand` for your company, product, or project name
- `.navbar-nav` for a full-height and lightweight navigation (including support for dropdowns)
2016-10-03 18:55:59 +02:00
- `.navbar-toggler` for use with our collapse plugin and other [navigation toggling ](#collapsible-content ) behaviors.
2016-10-19 09:18:47 +02:00
- Inline forms with `.float-` utilities for form controls and components.
- `.navbar-text` for adding vertically centered strings of text.
2016-12-21 22:08:34 +01:00
- `.inline-form` for form controls and more.
2014-10-27 12:49:24 +01:00
2016-12-21 22:08:34 +01:00
Here's an example of all the sub-components included in a responsive light-themed navbar.
2014-07-14 08:33:54 +02:00
2014-10-27 12:49:24 +01:00
{% example html %}
2015-08-18 09:46:29 +02:00
< nav class = "navbar navbar-light bg-faded" >
2015-08-18 08:43:59 +02:00
< a class = "navbar-brand" href = "#" > Navbar< / a >
< ul class = "nav navbar-nav" >
2014-07-14 08:33:54 +02:00
< li class = "nav-item active" >
2014-12-01 05:17:45 +01:00
< a class = "nav-link" href = "#" > Home < span class = "sr-only" > (current)< / span > < / a >
2014-07-14 08:33:54 +02:00
< / li >
< li class = "nav-item" >
2016-10-18 07:09:11 +02:00
< a class = "nav-link" href = "#" > Link< / a >
2014-07-14 08:33:54 +02:00
< / li >
< li class = "nav-item" >
2016-11-26 09:19:30 +01:00
< a class = "nav-link disabled" href = "#" > Disabled< / a >
2014-07-14 08:33:54 +02:00
< / li >
2016-10-18 07:09:11 +02:00
< li class = "nav-item dropdown" >
2016-10-18 08:37:02 +02:00
< a class = "nav-link dropdown-toggle" href = "http://example.com" id = "supportedContentDropdown" data-toggle = "dropdown" aria-haspopup = "true" aria-expanded = "false" > Dropdown< / a >
< div class = "dropdown-menu" aria-labelledby = "supportedContentDropdown" >
2016-10-18 07:09:11 +02:00
< 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 >
2014-07-14 08:33:54 +02:00
< / li >
< / ul >
2016-12-21 22:08:34 +01:00
< form class = "form-inline" >
2014-10-27 12:49:24 +01:00
< input class = "form-control" type = "text" placeholder = "Search" >
2016-01-06 10:32:39 +01:00
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
2014-10-27 12:49:24 +01:00
< / form >
2014-12-01 05:17:45 +01:00
< / nav >
2014-10-27 12:49:24 +01:00
{% endexample %}
2015-12-07 07:34:06 +01:00
### Brand
2016-02-09 07:13:30 +01:00
The `.navbar-brand` can be applied to most elements, but an anchor works best as some elements might require utility classes or custom styles.
2015-12-07 07:34:06 +01:00
{% example html %}
2016-05-13 04:47:49 +02:00
<!-- As a link -->
2015-12-07 07:34:06 +01:00
< nav class = "navbar navbar-light bg-faded" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
< / nav >
2016-05-13 04:47:49 +02:00
<!-- As a heading -->
2015-12-07 07:34:06 +01:00
< nav class = "navbar navbar-light bg-faded" >
2016-09-09 07:16:28 +02:00
< h1 class = "navbar-brand mb-0" > Navbar< / h1 >
2015-12-07 07:34:06 +01:00
< / nav >
{% endexample %}
2016-10-19 03:47:49 +02:00
Adding images to the `.navbar-brand` will likely always require custom styles or utilities to properly size. Here are some examples to demonstrate.
{% example html %}
<!-- Just an image -->
< nav class = "navbar navbar-light bg-faded" >
< a class = "navbar-brand" href = "#" >
2016-10-19 09:30:59 +02:00
< img src = "{{ site.baseurl }}/assets/brand/bootstrap-solid.svg" width = "30" height = "30" alt = "" >
2016-10-19 03:47:49 +02:00
< / a >
< / nav >
{% endexample %}
{% example html %}
<!-- Image and text -->
< nav class = "navbar navbar-light bg-faded" >
< a class = "navbar-brand" href = "#" >
2016-10-19 09:30:59 +02:00
< img src = "{{ site.baseurl }}/assets/brand/bootstrap-solid.svg" width = "30" height = "30" class = "d-inline-block align-top" alt = "" >
2016-10-19 03:47:49 +02:00
Bootstrap
< / a >
< / nav >
{% endexample %}
2015-12-07 07:34:06 +01:00
### Nav
2016-12-21 22:08:34 +01:00
Navbar navigation is similar to our regular nav options—use the `.nav` base class with the `.navbar-nav` modifier correctly position your links. **Navbar navigation will grow to occupy as much horizontal space as possible** to keep your navbar contents aligned properly.
2015-12-07 07:34:06 +01:00
2016-05-14 21:41:26 +02:00
Active states—with `.active` —to indicate the current page can be applied directly to `.nav-link` s or their immediate parent `.nav-item` s.
2015-12-07 07:34:06 +01:00
{% example html %}
< nav class = "navbar navbar-light bg-faded" >
< ul class = "nav navbar-nav" >
< li class = "nav-item active" >
< a class = "nav-link" href = "#" > Home < span class = "sr-only" > (current)< / span > < / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Features< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Pricing< / a >
< / li >
< li class = "nav-item" >
2016-11-26 09:19:30 +01:00
< a class = "nav-link disabled" href = "#" > Disabled< / a >
2015-12-07 07:34:06 +01:00
< / li >
< / ul >
< / nav >
{% endexample %}
2015-12-08 09:36:42 +01:00
And because we use classes for our navs, you can avoid the list-based approach entirely if you like.
2015-12-07 07:34:06 +01:00
{% example html %}
< nav class = "navbar navbar-light bg-faded" >
< div class = "nav navbar-nav" >
< a class = "nav-item nav-link active" href = "#" > Home < span class = "sr-only" > (current)< / span > < / a >
< a class = "nav-item nav-link" href = "#" > Features< / a >
< a class = "nav-item nav-link" href = "#" > Pricing< / a >
2016-11-26 09:19:30 +01:00
< a class = "nav-item nav-link disabled" href = "#" > Disabled< / a >
2015-12-07 07:34:06 +01:00
< / div >
< / nav >
{% endexample %}
2016-05-13 17:19:16 +02:00
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` and `.nav-link` as shown below.
{% example html %}
< nav class = "navbar navbar-light bg-faded" >
< ul class = "nav navbar-nav" >
< li class = "nav-item active" >
< a class = "nav-link" href = "#" > Home < span class = "sr-only" > (current)< / span > < / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Features< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Pricing< / a >
< / li >
< li class = "nav-item dropdown" >
2016-10-17 05:45:12 +02:00
< a class = "nav-link dropdown-toggle" href = "http://example.com" id = "navbarDropdownMenuLink" data-toggle = "dropdown" aria-haspopup = "true" aria-expanded = "false" >
2016-05-13 17:19:16 +02:00
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 >
< / nav >
{% endexample %}
2016-10-19 09:18:47 +02:00
### Forms
2016-12-21 22:08:34 +01:00
Place various form controls and components within a navbar with `.form-inline` .
2016-10-19 09:18:47 +02:00
{% example html %}
< nav class = "navbar navbar-light bg-faded" >
2016-12-21 22:08:34 +01:00
< form class = "form-inline" >
< input class = "form-control" type = "text" placeholder = "Search" >
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
< / form >
< / nav >
{% endexample %}
Align the contents of your inline forms with utilities as needed.
{% example html %}
< nav class = "navbar navbar-light bg-faded flex-items-right" >
< form class = "form-inline" >
2016-10-19 09:18:47 +02:00
< input class = "form-control" type = "text" placeholder = "Search" >
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
< / form >
< / nav >
{% endexample %}
Input groups work, too:
{% example html %}
< nav class = "navbar navbar-light bg-faded" >
2016-12-21 22:08:34 +01:00
< form class = "form-inline" >
2016-10-19 09:18:47 +02:00
< div class = "input-group" >
< span class = "input-group-addon" id = "basic-addon1" > @< / span >
< input type = "text" class = "form-control" placeholder = "Username" aria-describedby = "basic-addon1" >
< / div >
< / form >
< / nav >
{% endexample %}
2016-12-21 22:08:34 +01:00
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.
2016-10-19 09:18:47 +02:00
{% example html %}
< nav class = "navbar navbar-light bg-faded" >
2016-12-21 22:08:34 +01:00
< form class = "form-inline" >
2016-10-19 09:18:47 +02:00
< button class = "btn btn-outline-success" type = "button" > Main button< / button >
< button class = "btn btn-sm align-middle btn-outline-secondary" type = "button" > Smaller button< / button >
< / form >
< / nav >
{% endexample %}
2016-05-15 21:29:56 +02:00
### Text
Navbars may contain bits of text with the help of `.navbar-text` . This class adjusts vertical alignment and horizontal spacing for strings of text.
{% example html %}
< nav class = "navbar navbar-light bg-faded" >
2016-05-15 21:37:47 +02:00
< span class = "navbar-text" >
Navbar text with an inline element
< / span >
2016-05-15 21:29:56 +02:00
< / nav >
{% endexample %}
2015-08-18 09:46:29 +02:00
## Color schemes
2014-10-27 12:49:24 +01:00
2016-12-21 22:08:34 +01:00
Theming the navbar has never been easier thanks to the combination of theming classes and `background-color` utilities. Chose from `.navbar-light` for use with light background colors, or `.navbar-dark` for dark background colors. Then, customize with `.bg-*` utilities.
2015-08-18 09:46:29 +02:00
< div class = "bd-example" >
< nav class = "navbar navbar-dark bg-inverse" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
< ul class = "nav navbar-nav" >
< li class = "nav-item active" >
< a class = "nav-link" href = "#" > Home < span class = "sr-only" > (current)< / span > < / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Features< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Pricing< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > About< / a >
< / li >
< / ul >
2016-12-21 22:08:34 +01:00
< form class = "form-inline" >
2015-08-18 09:46:29 +02:00
< input class = "form-control" type = "text" placeholder = "Search" >
2016-01-06 10:32:39 +01:00
< button class = "btn btn-outline-info" type = "submit" > Search< / button >
2015-08-18 09:46:29 +02:00
< / form >
< / nav >
< nav class = "navbar navbar-dark bg-primary" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
< ul class = "nav navbar-nav" >
< li class = "nav-item active" >
< a class = "nav-link" href = "#" > Home < span class = "sr-only" > (current)< / span > < / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Features< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Pricing< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > About< / a >
< / li >
< / ul >
2016-12-21 22:08:34 +01:00
< form class = "form-inline" >
2015-08-18 09:46:29 +02:00
< input class = "form-control" type = "text" placeholder = "Search" >
2016-01-06 10:32:39 +01:00
< button class = "btn btn-outline-secondary" type = "submit" > Search< / button >
2015-08-18 09:46:29 +02:00
< / form >
< / nav >
< nav class = "navbar navbar-light" style = "background-color: #e3f2fd ;" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
< ul class = "nav navbar-nav" >
< li class = "nav-item active" >
< a class = "nav-link" href = "#" > Home < span class = "sr-only" > (current)< / span > < / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Features< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Pricing< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > About< / a >
< / li >
< / ul >
2016-12-21 22:08:34 +01:00
< form class = "form-inline" >
2015-08-18 09:46:29 +02:00
< input class = "form-control" type = "text" placeholder = "Search" >
2016-01-06 10:32:39 +01:00
< button class = "btn btn-outline-primary" type = "submit" > Search< / button >
2015-08-18 09:46:29 +02:00
< / form >
< / nav >
< / div >
{% highlight html %}
< nav class = "navbar navbar-dark bg-inverse" >
<!-- Navbar content -->
2014-12-01 05:17:45 +01:00
< / nav >
2015-08-18 09:46:29 +02:00
< nav class = "navbar navbar-dark bg-primary" >
<!-- Navbar content -->
< / nav >
< nav class = "navbar navbar-light" style = "background-color: #e3f2fd ;" >
<!-- Navbar content -->
< / nav >
{% endhighlight %}
2014-07-14 08:33:54 +02:00
2015-08-18 08:43:59 +02:00
## Containers
2015-06-23 01:30:52 +02:00
2015-12-07 07:47:23 +01:00
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 ](#placement ).
2015-04-19 03:12:10 +02:00
2015-08-18 08:43:59 +02:00
{% example html %}
< div class = "container" >
2015-08-18 09:46:29 +02:00
< nav class = "navbar navbar-light bg-faded" >
2015-08-18 08:43:59 +02:00
< a class = "navbar-brand" href = "#" > Navbar< / a >
2015-06-23 08:24:55 +02:00
< / nav >
< / div >
2015-08-18 08:43:59 +02:00
{% endexample %}
2015-06-23 08:24:55 +02:00
2015-08-18 08:43:59 +02:00
{% example html %}
2015-08-18 09:46:29 +02:00
< nav class = "navbar navbar-light bg-faded" >
2015-08-18 08:43:59 +02:00
< div class = "container" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
< / div >
2015-04-19 03:12:10 +02:00
< / nav >
2015-08-18 08:43:59 +02:00
{% endexample %}
2015-04-19 03:12:10 +02:00
2015-08-18 10:18:21 +02:00
## Placement
2015-09-06 05:58:28 +02:00
Navbars can be statically placed (their default behavior), static without rounded corners, or fixed to the top or bottom of the viewport.
{% example html %}
2016-12-21 22:14:48 +01:00
< nav class = "navbar navbar-light bg-faded" >
2015-09-06 05:58:28 +02:00
< a class = "navbar-brand" href = "#" > Full width< / a >
< / nav >
{% endexample %}
2015-08-18 10:18:21 +02:00
{% example html %}
< nav class = "navbar navbar-fixed-top navbar-light bg-faded" >
< a class = "navbar-brand" href = "#" > Fixed top< / a >
< / nav >
{% endexample %}
{% example html %}
< nav class = "navbar navbar-fixed-bottom navbar-light bg-faded" >
< a class = "navbar-brand" href = "#" > Fixed bottom< / a >
< / nav >
{% endexample %}
2015-08-18 08:43:59 +02:00
## Collapsible content
2014-07-14 08:33:54 +02:00
2014-12-01 05:17:45 +01:00
Our collapse plugin allows you to use a `<button>` or `<a>` to toggle hidden content.
2014-10-27 12:49:24 +01:00
{% example html %}
2015-08-18 09:46:29 +02:00
< nav class = "navbar navbar-light bg-faded" >
2016-07-08 10:54:53 +02:00
< button class = "navbar-toggler" type = "button" data-toggle = "collapse" data-target = "#exCollapsingNavbar" aria-controls = "exCollapsingNavbar" aria-expanded = "false" aria-label = "Toggle navigation" > < / button >
2015-12-24 19:10:37 +01:00
< div class = "collapse" id = "exCollapsingNavbar" >
2016-10-10 00:04:32 +02:00
< div class = "bg-inverse text-muted p-1" >
2015-12-24 19:10:37 +01:00
< h4 > Collapsed content< / h4 >
< span class = "text-muted" > Toggleable via the navbar brand.< / span >
< / div >
< / div >
2014-12-01 05:17:45 +01:00
< / nav >
2014-10-27 12:49:24 +01:00
{% endexample %}
2015-04-17 03:50:32 +02:00
For more complex navbar patterns, like those used in Bootstrap v3, use the `.navbar-toggleable-*` classes in conjunction with the `.navbar-toggler` . These classes override our responsive utilities to show navigation only when content is meant to be shown.
{% example html %}
2015-08-18 09:46:29 +02:00
< nav class = "navbar navbar-light bg-faded" >
2016-10-18 08:37:02 +02:00
< button class = "navbar-toggler hidden-lg-up" type = "button" data-toggle = "collapse" data-target = "#navbarResponsive" aria-controls = "navbarResponsive" aria-expanded = "false" aria-label = "Toggle navigation" > < / button >
2016-10-18 07:09:11 +02:00
< div class = "collapse navbar-toggleable-md" id = "navbarResponsive" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2015-08-18 08:43:59 +02:00
< ul class = "nav navbar-nav" >
< li class = "nav-item active" >
< a class = "nav-link" href = "#" > Home < span class = "sr-only" > (current)< / span > < / a >
< / li >
< li class = "nav-item" >
2016-10-18 07:09:11 +02:00
< a class = "nav-link" href = "#" > Link< / a >
2015-08-18 08:43:59 +02:00
< / li >
< li class = "nav-item" >
2016-10-18 07:09:11 +02:00
< a class = "nav-link" href = "#" > Link< / a >
2015-08-18 08:43:59 +02:00
< / li >
2016-10-18 07:09:11 +02:00
< li class = "nav-item dropdown" >
2016-10-18 08:45:25 +02:00
< a class = "nav-link dropdown-toggle" href = "http://example.com" id = "responsiveNavbarDropdown" data-toggle = "dropdown" aria-haspopup = "true" aria-expanded = "false" > Dropdown< / a >
< div class = "dropdown-menu" aria-labelledby = "responsiveNavbarDropdown" >
2016-10-18 07:09:11 +02:00
< 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 >
2015-08-18 08:43:59 +02:00
< / li >
< / ul >
2016-10-18 07:09:11 +02:00
< form class = "form-inline float-lg-right" >
< input class = "form-control" type = "text" placeholder = "Search" >
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
< / form >
2015-04-17 03:50:32 +02:00
< / div >
< / nav >
{% endexample %}