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
2017-05-28 08:01:14 +02:00
description: Documentation and examples for Bootstrap's powerful, responsive navigation header, the navbar. Includes support for branding, navigation, and more, including support for our collapse plugin.
2015-08-06 02:47:45 +02:00
group: components
2017-05-28 08:01:14 +02:00
toc: true
2014-07-14 08:33:54 +02:00
---
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:
2020-04-13 23:40:47 +02:00
- Navbars require a wrapping `.navbar` with `.navbar-expand{-sm|-md|-lg|-xl|-xxl}` for responsive collapsing and [color scheme ](#color-schemes ) classes.
2019-10-28 04:26:52 +01:00
- Navbars and their contents are fluid by default. Change the [container ](#containers ) to limit their horizontal width in different ways.
2019-02-04 11:22:02 +01:00
- Use our [spacing ]({{< docsref "/utilities/spacing" >}} ) and [flex ]({{< docsref "/utilities/flex" >}} ) utility classes for controlling spacing and alignment within navbars.
2016-12-21 22:12:55 +01:00
- 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.
2020-02-07 12:18:30 +01:00
- Indicate the current item by using `aria-current="page"` for the current page or `aria-current="true"` for the current item in a set.
2014-10-27 12:49:24 +01:00
2020-10-13 15:37:21 +02:00
{{< callout info > }}
2019-01-08 17:33:28 +01:00
{{< partial " callout-info-prefersreducedmotion . md " > }}
2020-10-13 15:37:21 +02:00
{{< / callout > }}
2018-11-03 19:23:26 +01:00
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
2016-12-29 01:36:55 +01:00
- `.navbar-brand` for your company, product, or project name.
- `.navbar-nav` for a full-height and lightweight navigation (including support for dropdowns).
2017-01-05 01:11:50 +01:00
- `.navbar-toggler` for use with our collapse plugin and other [navigation toggling ](#responsive-behaviors ) behaviors.
2019-09-28 16:14:33 +02:00
- Flex and spacing utilities for any form controls and actions.
2016-10-19 09:18:47 +02:00
- `.navbar-text` for adding vertically centered strings of text.
2016-12-22 02:52:28 +01:00
- `.collapse.navbar-collapse` for grouping and hiding navbar contents by a parent breakpoint.
2021-01-19 06:32:18 +01:00
- Add an optional `.navbar-scroll` to set a `max-height` and [scroll expanded navbar content ](#scrolling ).
2014-10-27 12:49:24 +01:00
2017-01-14 05:05:33 +01:00
Here's an example of all the sub-components included in a responsive light-themed navbar that automatically collapses at the `lg` (large) breakpoint.
2014-07-14 08:33:54 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarSupportedContent" aria-controls = "navbarSupportedContent" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarSupportedContent" >
2020-06-09 15:44:20 +02:00
< ul class = "navbar-nav me-auto mb-2 mb-lg-0" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01:00
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Link< / a >
< / li >
< li class = "nav-item dropdown" >
2020-07-22 21:33:11 +02:00
< a class = "nav-link dropdown-toggle" href = "#" id = "navbarDropdown" role = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
2019-10-28 04:26:52 +01:00
Dropdown
< / a >
< ul class = "dropdown-menu" aria-labelledby = "navbarDropdown" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< / ul >
< / li >
< li class = "nav-item" >
< a class = "nav-link disabled" href = "#" tabindex = "-1" aria-disabled = "true" > Disabled< / a >
< / li >
< / ul >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2016-12-21 22:17:48 +01:00
< / div >
2014-12-01 05:17:45 +01:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2014-10-27 12:49:24 +01:00
2021-01-16 23:06:19 +01:00
This example uses [background ]({{< docsref "/utilities/background" >}} ) (`bg-light`) and [spacing ]({{< docsref "/utilities/spacing" >}} ) (`my-2`, `my-lg-0` , `me-sm-0` , `my-sm-0` ) utility classes.
2017-10-18 19:26:33 +02:00
2015-12-07 07:34:06 +01:00
### Brand
2020-11-09 06:18:17 +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
2019-01-08 17:33:28 +01:00
{{< example > }}
2016-05-13 04:47:49 +02:00
<!-- As a link -->
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
< / div >
2015-12-07 07:34:06 +01:00
< / nav >
2016-05-13 04:47:49 +02:00
<!-- As a heading -->
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< span class = "navbar-brand mb-0 h1" > Navbar< / span >
< / div >
2015-12-07 07:34:06 +01:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-12-07 07:34:06 +01:00
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.
2019-01-08 17:33:28 +01:00
{{< example > }}
2016-10-19 03:47:49 +02:00
<!-- Just an image -->
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container" >
< a class = "navbar-brand" href = "#" >
2020-07-08 11:55:12 +02:00
< img src = "/docs/{{< param docs_version >}}/assets/brand/bootstrap-logo.svg" alt = "" width = "30" height = "24" >
2019-10-28 04:26:52 +01:00
< / a >
< / div >
2016-10-19 03:47:49 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-10-19 03:47:49 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2016-10-19 03:47:49 +02:00
<!-- Image and text -->
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" >
2020-07-08 11:55:12 +02:00
< img src = "/docs/{{< param docs_version >}}/assets/brand/bootstrap-logo.svg" alt = "" width = "30" height = "24" class = "d-inline-block align-top" >
2019-10-28 04:26:52 +01:00
Bootstrap
< / a >
< / div >
2016-10-19 03:47:49 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-10-19 03:47:49 +02:00
2015-12-07 07:34:06 +01:00
### Nav
2016-12-22 06:25:14 +01:00
Navbar navigation links build on our `.nav` options with their own modifier class and require the use of [toggler classes ](#toggler ) 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.
2015-12-07 07:34:06 +01:00
2021-01-07 08:24:57 +01:00
Add the `.active` class on `.nav-link` to indicate the current page.
2016-05-14 21:41:26 +02:00
2021-01-07 08:24:57 +01:00
Please note that you should also add the `aria-current` attribute on the active `.nav-link` .
2020-02-07 12:18:30 +01:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarNav" aria-controls = "navbarNav" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarNav" >
< ul class = "navbar-nav" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01: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 disabled" href = "#" tabindex = "-1" aria-disabled = "true" > Disabled< / a >
< / li >
< / ul >
< / div >
2016-12-22 06:25:14 +01:00
< / div >
2015-12-07 07:34:06 +01:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-12-07 07:34:06 +01:00
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
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarNavAltMarkup" aria-controls = "navbarNavAltMarkup" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarNavAltMarkup" >
< div class = "navbar-nav" >
2020-06-05 20:57:35 +02:00
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
< a class = "nav-link" href = "#" > Features< / a >
< a class = "nav-link" href = "#" > Pricing< / a >
< a class = "nav-link disabled" href = "#" tabindex = "-1" aria-disabled = "true" > Disabled< / a >
2019-10-28 04:26:52 +01:00
< / div >
2016-12-22 06:25:14 +01:00
< / div >
2015-12-07 07:34:06 +01:00
< / div >
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-12-07 07:34:06 +01:00
2020-11-09 06:18:17 +01:00
You can also use dropdowns in your navbar. 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.
2016-05-13 17:19:16 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarNavDropdown" aria-controls = "navbarNavDropdown" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarNavDropdown" >
< ul class = "navbar-nav" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01: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 dropdown" >
2020-07-22 21:33:11 +02:00
< a class = "nav-link dropdown-toggle" href = "#" id = "navbarDropdownMenuLink" role = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
2019-10-28 04:26:52 +01:00
Dropdown link
< / a >
< ul class = "dropdown-menu" aria-labelledby = "navbarDropdownMenuLink" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< / ul >
< / li >
< / ul >
< / div >
2016-12-22 06:25:14 +01:00
< / div >
2016-05-13 17:19:16 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-05-13 17:19:16 +02:00
2016-10-19 09:18:47 +02:00
### Forms
2019-09-28 16:14:33 +02:00
Place various form controls and components within a navbar:
2016-10-19 09:18:47 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2016-12-21 22:08:34 +01:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-12-21 22:08:34 +01:00
2020-11-09 06:18:17 +01:00
Immediate child elements of `.navbar` use flex layout and will default to `justify-content: space-between` . Use additional [flex utilities ]({{< docsref "/utilities/flex" >}} ) as needed to adjust this behavior.
2016-12-21 22:08:34 +01:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2018-03-31 23:59:03 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" > Navbar< / a >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2016-10-19 09:18:47 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-10-19 09:18:47 +02:00
2020-11-09 06:18:17 +01:00
Input groups work, too. If your navbar is an entire form, or mostly a form, you can use the `<form>` element as the container and save some HTML.
2016-10-19 09:18:47 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-09-28 16:14:33 +02:00
< form class = "container-fluid" >
< div class = "input-group" >
2019-12-19 15:28:40 +01:00
< span class = "input-group-text" id = "basic-addon1" > @< / span >
2019-09-28 16:14:33 +02:00
< input type = "text" class = "form-control" placeholder = "Username" aria-label = "Username" aria-describedby = "basic-addon1" >
< / div >
< / form >
2016-10-19 09:18:47 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-10-19 09:18:47 +02:00
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
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-09-28 16:14:33 +02:00
< form class = "container-fluid justify-content-start" >
2020-06-09 15:44:20 +02:00
< button class = "btn btn-outline-success me-2" type = "button" > Main button< / button >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-sm btn-outline-secondary" type = "button" > Smaller button< / button >
< / form >
2016-10-19 09:18:47 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-10-19 09:18:47 +02:00
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.
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
2016-12-22 06:25:14 +01:00
< span class = "navbar-text" >
Navbar text with an inline element
< / span >
< / div >
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-12-22 06:25:14 +01:00
2019-10-28 04:26:52 +01:00
Mix and match with other components and utilities as needed.
2015-08-18 09:46:29 +02:00
2019-10-28 04:26:52 +01:00
{{< example > }}
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar w/ text< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarText" aria-controls = "navbarText" aria-expanded = "false" aria-label = "Toggle navigation" >
2017-03-21 07:13:34 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
2019-10-28 04:26:52 +01:00
< div class = "collapse navbar-collapse" id = "navbarText" >
2020-06-09 15:44:20 +02:00
< ul class = "navbar-nav me-auto mb-2 mb-lg-0" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2016-12-22 03:29:51 +01: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 >
< / ul >
2019-10-28 04:26:52 +01:00
< span class = "navbar-text" >
Navbar text with an inline element
< / span >
< / div >
< / div >
< / nav >
{{< / example > }}
## Color schemes
Theming the navbar has never been easier thanks to the combination of theming classes and `background-color` utilities. Choose from `.navbar-light` for use with light background colors, or `.navbar-dark` for dark background colors. Then, customize with `.bg-*` utilities.
< div class = "bd-example" >
< nav class = "navbar navbar-expand-lg navbar-dark bg-dark" >
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarColor01" aria-controls = "navbarColor01" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarColor01" >
2020-06-09 15:44:20 +02:00
< ul class = "navbar-nav me-auto mb-2 mb-lg-0" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01: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 >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2020-03-30 14:07:09 +02:00
< button class = "btn btn-outline-light" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2016-12-22 03:29:51 +01:00
< / div >
2015-08-18 09:46:29 +02:00
< / nav >
2016-12-22 03:29:51 +01:00
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-dark bg-primary" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarColor02" aria-controls = "navbarColor02" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarColor02" >
2020-06-09 15:44:20 +02:00
< ul class = "navbar-nav me-auto mb-2 mb-lg-0" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01: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 >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-outline-light" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2016-12-22 03:29:51 +01:00
< / div >
2015-08-18 09:46:29 +02:00
< / nav >
2016-12-22 03:29:51 +01:00
2017-04-02 21:44:38 +02:00
< nav class = "navbar navbar-expand-lg navbar-light" style = "background-color: #e3f2fd ;" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarColor03" aria-controls = "navbarColor03" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarColor03" >
2020-06-09 15:44:20 +02:00
< ul class = "navbar-nav me-auto mb-2 mb-lg-0" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01: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 >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-outline-primary" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2019-09-28 16:14:33 +02:00
< / div >
2015-08-18 09:46:29 +02:00
< / nav >
< / div >
2020-10-19 11:56:49 +02:00
```html
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-dark bg-dark" >
2015-08-18 09:46:29 +02:00
<!-- Navbar content -->
2014-12-01 05:17:45 +01:00
< / nav >
2015-08-18 09:46:29 +02:00
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-dark bg-primary" >
2015-08-18 09:46:29 +02:00
<!-- Navbar content -->
< / nav >
< nav class = "navbar navbar-light" style = "background-color: #e3f2fd ;" >
<!-- Navbar content -->
< / nav >
2020-10-19 11:56:49 +02:00
```
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
2020-11-09 06:18:17 +01:00
Although it's not required, you can wrap a navbar in a `.container` to center it on a page– though note that an inner container is still required. Or you can add a container inside the `.navbar` to only center the contents of a [fixed or static top navbar ](#placement ).
2015-04-19 03:12:10 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2015-08-18 08:43:59 +02:00
< div class = "container" >
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
< / div >
2015-06-23 08:24:55 +02:00
< / nav >
< / div >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-06-23 08:24:55 +02:00
2020-11-09 06:18:17 +01:00
Use any of the responsive containers to change how wide the content in your navbar is presented.
2016-12-22 06:38:02 +01:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-md" >
2015-08-18 08:43:59 +02:00
< a class = "navbar-brand" href = "#" > Navbar< / a >
< / div >
2015-04-19 03:12:10 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-04-19 03:12:10 +02:00
2015-08-18 10:18:21 +02:00
## Placement
2019-02-04 11:22:02 +01:00
Use our [position utilities ]({{< docsref "/utilities/position" >}} ) 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.
2017-10-18 19:26:33 +02:00
2020-11-12 14:01:00 +01:00
Also note that ** `.sticky-top` uses `position: sticky` , which [isn't fully supported in every browser ](https://caniuse.com/css-sticky )**.
2015-09-06 05:58:28 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Default< / a >
< / div >
2015-09-06 05:58:28 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-08-18 10:18:21 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar fixed-top navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Fixed top< / a >
< / div >
2015-08-18 10:18:21 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-08-18 10:18:21 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar fixed-bottom navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Fixed bottom< / a >
< / div >
2015-08-18 10:18:21 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2015-08-18 10:18:21 +02:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar sticky-top navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Sticky top< / a >
< / div >
2017-01-02 20:48:05 +01:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2017-01-02 20:48:05 +01:00
2021-01-19 06:32:18 +01:00
## Scrolling
2021-01-20 11:12:35 +01:00
Add `.navbar-nav-scroll` to a `.navbar-nav` (or other navbar sub-component) to enable vertical scrolling within the toggleable contents of a collapsed navbar. By default, scrolling kicks in at `75vh` (or 75% of the viewport height), but you can override that with the local CSS custom property `--bs-navbar-height` or custom styles. At larger viewports when the navbar is expanded, content will appear as it does in a default navbar.
2021-01-19 06:32:18 +01:00
Please note that this behavior comes with a potential drawback of `overflow` —when setting `overflow-y: auto` (required to scroll the content here), `overflow-x` is the equivalent of `auto` , which will crop some horizontal content.
Here's an example navbar using `.navbar-nav-scroll` with `style="--bs-scroll-height: 100px;"` , with some extra margin utilities for optimum spacing.
{{< example > }}
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar scroll< / a >
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarScroll" aria-controls = "navbarScroll" aria-expanded = "false" aria-label = "Toggle navigation" >
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarScroll" >
< ul class = "navbar-nav me-auto my-2 my-lg-0 navbar-nav-scroll" style = "--bs-scroll-height: 100px;" >
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Link< / a >
< / li >
< li class = "nav-item dropdown" >
< a class = "nav-link dropdown-toggle" href = "#" id = "navbarScrollingDropdown" role = "button" data-bs-toggle = "dropdown" aria-expanded = "false" >
Link
< / a >
< ul class = "dropdown-menu" aria-labelledby = "navbarScrollingDropdown" >
< li > < a class = "dropdown-item" href = "#" > Action< / a > < / li >
< li > < a class = "dropdown-item" href = "#" > Another action< / a > < / li >
< li > < hr class = "dropdown-divider" > < / li >
< li > < a class = "dropdown-item" href = "#" > Something else here< / a > < / li >
< / ul >
< / li >
< li class = "nav-item" >
< a class = "nav-link disabled" href = "#" tabindex = "-1" aria-disabled = "true" > Link< / a >
< / li >
< / ul >
< form class = "d-flex" >
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
< / form >
< / div >
< / div >
< / nav >
{{< / example > }}
2016-12-22 02:52:39 +01:00
## Responsive behaviors
2020-11-09 06:18:17 +01:00
Navbars can use `.navbar-toggler` , `.navbar-collapse` , and `.navbar-expand{-sm|-md|-lg|-xl|-xxl}` classes to determine when their content collapses behind a button. In combination with other utilities, you can easily choose when to show or hide particular elements.
2016-12-22 02:52:39 +01:00
2017-04-02 21:44:38 +02:00
For navbars that never collapse, add the `.navbar-expand` class on the navbar. For navbars that always collapse, don't add any `.navbar-expand` class.
2017-01-14 05:05:33 +01:00
2016-12-22 02:52:39 +01:00
### Toggler
2017-03-21 07:10:15 +01:00
Navbar togglers are left-aligned by default, but should they follow a sibling element like a `.navbar-brand` , 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.
2016-12-22 02:52:39 +01:00
2020-11-09 06:18:17 +01:00
With no `.navbar-brand` shown at the smallest breakpoint:
2016-12-22 02:52:39 +01:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarTogglerDemo01" aria-controls = "navbarTogglerDemo01" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarTogglerDemo01" >
< a class = "navbar-brand" href = "#" > Hidden brand< / a >
2020-06-09 15:44:20 +02:00
< ul class = "navbar-nav me-auto mb-2 mb-lg-0" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01:00
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Link< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link disabled" href = "#" tabindex = "-1" aria-disabled = "true" > Disabled< / a >
< / li >
< / ul >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2016-12-22 02:52:39 +01:00
< / div >
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-12-22 02:52:39 +01:00
With a brand name shown on the left and toggler on the right:
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
< a class = "navbar-brand" href = "#" > Navbar< / a >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarTogglerDemo02" aria-controls = "navbarTogglerDemo02" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< div class = "collapse navbar-collapse" id = "navbarTogglerDemo02" >
2020-06-09 15:44:20 +02:00
< ul class = "navbar-nav me-auto mb-2 mb-lg-0" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01:00
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Link< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link disabled" href = "#" tabindex = "-1" aria-disabled = "true" > Disabled< / a >
< / li >
< / ul >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2017-03-21 07:10:15 +01:00
< / div >
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2017-03-21 07:10:15 +01:00
With a toggler on the left and brand name on the right:
2019-01-08 17:33:28 +01:00
{{< example > }}
2017-06-26 03:29:43 +02:00
< nav class = "navbar navbar-expand-lg navbar-light bg-light" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarTogglerDemo03" aria-controls = "navbarTogglerDemo03" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< a class = "navbar-brand" href = "#" > Navbar< / a >
< div class = "collapse navbar-collapse" id = "navbarTogglerDemo03" >
2020-06-09 15:44:20 +02:00
< ul class = "navbar-nav me-auto mb-2 mb-lg-0" >
2020-05-20 14:56:42 +02:00
< li class = "nav-item" >
< a class = "nav-link active" aria-current = "page" href = "#" > Home< / a >
2019-10-28 04:26:52 +01:00
< / li >
< li class = "nav-item" >
< a class = "nav-link" href = "#" > Link< / a >
< / li >
< li class = "nav-item" >
< a class = "nav-link disabled" href = "#" tabindex = "-1" aria-disabled = "true" > Disabled< / a >
< / li >
< / ul >
2019-09-28 16:14:33 +02:00
< form class = "d-flex" >
2020-06-09 15:44:20 +02:00
< input class = "form-control me-2" type = "search" placeholder = "Search" aria-label = "Search" >
2019-09-28 16:14:33 +02:00
< button class = "btn btn-outline-success" type = "submit" > Search< / button >
2019-10-28 04:26:52 +01:00
< / form >
< / div >
2016-12-22 02:52:39 +01:00
< / div >
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2016-12-22 02:52:39 +01:00
### External content
2020-07-22 21:33:11 +02:00
Sometimes you want to use the collapse plugin to trigger a container element for content that structurally sits outside of the `.navbar` . Because our plugin works on the `id` and `data-bs-target` matching, that's easily done!
2016-12-22 02:52:39 +01:00
2019-01-08 17:33:28 +01:00
{{< example > }}
2019-06-06 08:04:48 +02:00
< div class = "collapse" id = "navbarToggleExternalContent" >
< div class = "bg-dark p-4" >
< h5 class = "text-white h4" > Collapsed content< / h5 >
< span class = "text-muted" > Toggleable via the navbar brand.< / span >
2016-12-22 02:52:39 +01:00
< / div >
< / div >
2019-06-06 08:04:48 +02:00
< nav class = "navbar navbar-dark bg-dark" >
2019-10-28 04:26:52 +01:00
< div class = "container-fluid" >
2020-07-22 21:33:11 +02:00
< button class = "navbar-toggler" type = "button" data-bs-toggle = "collapse" data-bs-target = "#navbarToggleExternalContent" aria-controls = "navbarToggleExternalContent" aria-expanded = "false" aria-label = "Toggle navigation" >
2019-10-28 04:26:52 +01:00
< span class = "navbar-toggler-icon" > < / span >
< / button >
< / div >
2019-06-06 08:04:48 +02:00
< / nav >
2019-01-08 17:33:28 +01:00
{{< / example > }}
2020-11-09 06:18:17 +01:00
When you do this, we recommend including additional JavaScript to move the focus programmatically to the container when it is opened. Otherwise, keyboard users and users of assistive technologies will likely have a hard time finding the newly revealed content - particularly if the container that was opened comes *before* the toggler in the document's structure. We also recommend making sure that the toggler has the `aria-controls` attribute, pointing to the `id` of the content container. In theory, this allows assistive technology users to jump directly from the toggler to the container it controls– but support for this is currently quite patchy.
2021-02-11 04:29:59 +01:00
## Sass
### Variables
{{< scss-docs name = "navbar-variables" file = "scss/_variables.scss" > }}
{{< scss-docs name = "navbar-theme-variables" file = "scss/_variables.scss" > }}
### Loop
[Responsive navbar expand/collapse classes ](#responsive-behaviors ) (e.g., `.navbar-expand-lg` ) are combined with the `$breakpoints` map and generated through a loop in `scss/_navbar.scss` .
{{< scss-docs name = "navbar-expand-loop" file = "scss/_navbar.scss" > }}