Create responsive navigation header, the navbar which includes support for branding, navigation, forms and more, including support for collapse plugin.
.navbar
with .navbar-expand{-sm|-md|-lg|-xl}
for responsive collapsing and color scheme classes..d-print
to the .navbar
. See the display utility class.<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.You can add below sub-components within a navbar.
.navbar-brand
for your company, product, or project name..navbar-nav
for a full-height and lightweight navigation (including support for dropdowns)..navbar-toggler
for use with our collapse plugin and other navigation togglingbehaviors..form-inline
for any form controls and actions..navbar-text
for adding vertically centered strings of text..collapse.navbar-collapse
for grouping and hiding navbar contents by a parent breakpoint.The below example uses light-themed (bg-light
) navbar and for spacing uses utility classes(my-2
, my-lg-0
, mr-sm-0
, my-sm-0
) that automatically collapses at the lg
(large) breakpoint.
Add your site name(brand) inside a anchor with .navbar-brand
class. .navbar-brand
can be applied to most elements other than anchor, but other elements might require some utility classes or custom styles.
Adding images to the .navbar-brand
. You might require custom styles or utilities size properly.
Create navbar navigation links .navbar-nav
on the unordered list. It 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 aligned properly.
Indicate active states with .active
for the current page which can be applied directly to .nav-link
s or their immediate parent .nav-item
s.
You can also create navbar without using unordered list.
Dropdown menus require a wrapping element for positioning. So use separate and nested elements for .nav-item
and .nav-link
.
Place various form controls and components within a navbar with .form-inline
.
Immediate children elements in .navbar
use flex layout and will default to justify-content: between
. Use flex utilities as needed to adjust this behavior.
Input groups also work with navbar.
You can also add buttons as part of these navbar forms.
Navbars can contain text with the help of .navbar-text
. This class adjusts vertical alignment and horizontal spacing for strings of text.
Below example contains few components and utilities.
Navbar can be colored using 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. You could also use custom inline-styles or css for background colors.
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.
When the container is within your navbar, its horizontal padding is removed at breakpoints lower than your specified .navbar-expand{-sm|-md|-lg|-xl}
class. This removes unnecessarily doubling up on padding on lower viewports when your navbar is collapsed.
Place the navbar using position utilities as needed. It supports .fixed-top(fixed to the top), .fixed-bottom(fixed to the bottom), or .sticky-top(sticked to the top) (scrolls with the page until it reaches the top, then stays there).
Fixed navbars use position: fixed
which may require custom CSS (e.g., padding-top
on the <body>
) to prevent overlap with other elements.
Navbars can utilize .navbar-toggler
, .navbar-collapse
, and .navbar-expand{-sm|-md|-lg|-xl}
classes to change when their content collapses behind a button. You can easily choose when to show or hide particular elements in combination with other utilities.
.navbar-expand
class on the navbar..navbar-expand
class.By default navbar togglers are left-aligned, 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.
With no .navbar-brand
shown in lowest breakpoint.
With a brand name shown on the left and toggler on the right
With a toggler on the left and brand name on the right:
You want to use the collapse plugin to trigger hidden content elsewhere on the page. Because plugin works on the id
and matching data-target