2014-07-14 08:33:54 +02:00
---
layout: page
2014-10-27 12:52:48 +01:00
title: Navbar
2015-08-06 02:47:45 +02:00
group: components
2014-07-14 08:33:54 +02:00
---
2014-10-27 12:49:24 +01:00
The navbar is a simple wrapper for positioning branding, navigation, and other elements. It's easily extensible and with the help of our collapse plugin it can easily integrate offscreen content.
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}
2014-10-27 12:49:24 +01:00
### Basics
Here's what you need to know before getting started with the navbar:
- Navbars require a wrapping `.navbar` and either a color scheme class or custom styles.
- When using multiple components in a navbar, some [alignment classes ](#alignment ) are required.
- Navbars and their contents are fluid by default. Use [optional containers ](#containers ) to limit their horizontal width.
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
### Branding
Name your company, product, or project with `.navbar-brand` .
{% example html %}
2014-12-01 05:17:45 +01:00
< nav class = "navbar navbar-default" >
2014-10-27 12:49:24 +01:00
< h3 class = "navbar-brand" >
2014-07-14 08:33:54 +02:00
< a href = "#" > Navbar< / a >
< / h3 >
2014-12-01 05:17:45 +01:00
< / nav >
2014-10-27 12:49:24 +01:00
{% endexample %}
### Navigation
Use `.nav-pills` within a navbar for basic navigation.
2014-07-14 08:33:54 +02:00
2014-10-27 12:49:24 +01:00
{% example html %}
2014-12-01 05:17:45 +01:00
< nav class = "navbar navbar-default" >
2014-10-27 12:49:24 +01:00
< ul class = "nav nav-pills" >
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" >
< 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 >
2014-12-01 05:17:45 +01:00
< / nav >
2014-10-27 12:49:24 +01:00
{% endexample %}
### Inline forms
Add an `.inline-form` within the navbar with nearly any combination of form controls and buttons.
{% example html %}
2014-12-01 05:17:45 +01:00
< nav class = "navbar navbar-default" >
2014-10-27 12:49:24 +01:00
< form class = "form-inline" >
< input class = "form-control" type = "text" placeholder = "Search" >
< button class = "btn btn-primary" type = "submit" > Search< / button >
< / form >
2014-12-01 05:17:45 +01:00
< / nav >
2014-10-27 12:49:24 +01:00
{% endexample %}
### Containers
2015-06-23 01:30:52 +02: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 the navbar.
2014-10-27 12:49:24 +01:00
{% example html %}
2015-06-23 01:30:52 +02:00
< div class = "container" >
< nav class = "navbar navbar-default" >
2014-10-27 12:49:24 +01:00
< h3 class = "navbar-brand" >
< a href = "#" > Navbar< / a >
< / h3 >
2015-06-23 01:30:52 +02:00
< / nav >
< / div >
2014-10-27 12:49:24 +01:00
{% endexample %}
{% example html %}
2015-06-23 01:30:52 +02:00
< nav class = "navbar navbar-default" >
< div class = "container" >
2014-10-27 12:49:24 +01:00
< h3 class = "navbar-brand" >
< a href = "#" > Navbar< / a >
< / h3 >
2015-06-23 01:30:52 +02:00
< / div >
< / nav >
2014-10-27 12:49:24 +01:00
{% endexample %}
2014-07-14 08:33:54 +02:00
2014-10-27 12:49:24 +01:00
### Alignment
Use `.pull-left` or `.pull-right` to align multiple elements within the navbar.
{% example html %}
2014-12-01 05:17:45 +01:00
< nav class = "navbar navbar-default" >
2014-07-14 08:33:54 +02:00
< h3 class = "navbar-brand pull-left" >
< a href = "#" > Navbar< / a >
< / h3 >
< ul class = "nav nav-pills pull-left" >
< 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" >
< 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 >
< ul class = "nav nav-pills pull-right" >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Help< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Sign out< / a >
< / li >
< / ul >
2014-12-01 05:17:45 +01:00
< / nav >
2014-10-27 12:49:24 +01:00
{% endexample %}
2014-07-14 08:33:54 +02:00
2014-10-27 12:49:24 +01:00
### Inverse color scheme
Replace `.navbar-default` with `.navbar-inverse` for a darker background color and white text.
2014-07-14 08:33:54 +02:00
2014-10-27 12:49:24 +01:00
{% example html %}
2014-12-01 05:17:45 +01:00
< nav class = "navbar navbar-inverse" >
2014-07-14 08:33:54 +02:00
< h3 class = "navbar-brand pull-left" >
< a href = "#" > Navbar< / a >
< / h3 >
< ul class = "nav nav-pills pull-left" >
< 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" >
< 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 >
2014-09-18 00:21:31 +02:00
< form class = "form-inline pull-right" >
2014-07-14 08:33:54 +02:00
< input class = "form-control" type = "text" placeholder = "Search" >
< button class = "btn btn-primary" type = "submit" > Search< / button >
< / form >
2014-12-01 05:17:45 +01:00
< / nav >
2014-10-27 12:49:24 +01:00
{% endexample %}
2014-07-14 08:33:54 +02:00
2015-06-23 01:30:52 +02:00
### Small navbar
Small navbars provide a similar aesthetic to Bootstrap 3's navbar. It cuts the padding down, enables full-height navigation, and tweaks vertical alignment for search forms, buttons, and more. It's also available in both default and inverse schemes.
2015-04-19 03:12:10 +02:00
2015-06-23 01:30:52 +02:00
When moving from a regular navbar to a small one, be sure to update your inputs and buttons to use their small variations as well.
2015-04-19 03:12:10 +02:00
2015-06-23 08:24:55 +02:00
< div class = "bd-example" >
< nav class = "navbar navbar-default navbar-sm" >
< h3 class = "navbar-brand pull-left" >
< a href = "#" > Navbar< / a >
< / h3 >
< ul class = "nav navbar-nav pull-left" >
< 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 >
< form class = "form-inline pull-right" >
< input class = "form-control form-control-sm" type = "text" placeholder = "Search" >
< button class = "btn btn-sm btn-primary" type = "submit" > Search< / button >
< / form >
< / nav >
< nav class = "navbar navbar-inverse navbar-sm" >
< h3 class = "navbar-brand pull-left" >
< a href = "#" > Navbar< / a >
< / h3 >
< ul class = "nav navbar-nav pull-left" >
< 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 >
< form class = "form-inline pull-right" >
< input class = "form-control form-control-sm" type = "text" placeholder = "Search" >
< button class = "btn btn-sm btn-primary" type = "submit" > Search< / button >
< / form >
< / nav >
< / div >
{% highlight html %}
2015-06-23 01:30:52 +02:00
< nav class = "navbar navbar-default navbar-sm" >
2015-06-23 08:24:55 +02:00
<!-- Navbar contents -->
2015-04-19 03:12:10 +02:00
< / nav >
2015-06-23 01:30:52 +02:00
< nav class = "navbar navbar-inverse navbar-sm" >
2015-06-23 08:24:55 +02:00
<!-- Navbar contents -->
2015-04-19 03:12:10 +02:00
< / nav >
2015-06-23 08:24:55 +02:00
{% endhighlight %}
2015-04-19 03:12:10 +02:00
2014-10-27 12:49:24 +01: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-04-17 03:50:32 +02:00
< div class = "collapse" id = "exCollapsingNavbar" >
2014-07-14 17:48:33 +02:00
< div class = "inverse p-a" >
2015-04-17 03:50:32 +02:00
< h4 > Collapsed content< / h4 >
2014-07-14 08:33:54 +02:00
< p > Toggleable via the navbar brand.< / p >
< / div >
2014-07-14 17:48:33 +02:00
< / div >
2014-12-01 05:17:45 +01:00
< nav class = "navbar navbar-default" >
2015-04-17 03:50:32 +02:00
< button class = "navbar-toggler" type = "button" data-toggle = "collapse" data-target = "#exCollapsingNavbar" >
2014-07-14 08:33:54 +02:00
☰
< / button >
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 %}
< nav class = "navbar navbar-default" >
< button class = "navbar-toggler hidden-sm-up" type = "button" data-toggle = "collapse" data-target = "#exCollapsingNavbar2" >
☰
< / button >
< div class = "collapse navbar-toggleable-xs" id = "exCollapsingNavbar2" >
< h4 > Collapsed on xs devices< / h4 >
< p > Toggleable via the navbar brand.< / p >
< / div >
< / nav >
{% endexample %}