Bootstrap - navbar



This chapter will discuss about Bootstrap navbar. Bootstrap's navbar is a powerful and responsive navigation header. A navigation bar is a navigation header located at the top of the page.

How it works

  • Basic navbar is built using .navbar class. For responsive collapsing wrap the class .navbar with .navbar-expand{-sm|-md|-lg|-xl|-xxl} (arranging the navbar vertically on small, medium, large, extra large or xxlarge screens).

  • Utilizing aria-current="page" indicates the current item or aria-current="true" indicates current item in a set.

  • Ensure availability by employing an

  • New in v5.2.0: Navbars can be themed with CSS variables themed using CSS variables restricted to the .navbar base class. .navbar-light has been deplored and the .navbar-dark has been rewritten to abrogate CSS factors rather than including extra styles.

Basic navbar

Supported content

Built-in classes come in handy while using navbars as listed below:

  • Use class .navbar-brand for a company, product, or project name.

  • Use .navbar-nav for full-height, lightweight navigation (includes support for dropdowns).

  • Use class .navbar-toggler with collapse plugin for navigational toggling behavior.

  • Use class .navbar-text for adding vertically centered strings of text..

  • Use .collapse.navbar-collapse to the group and collapse the navbar content by a parent breakpoint.

  • Use .navbar-scroll to set the maximum height and scroll the expanded content of the navbar.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Vertical navbar

To create a navigation bar that will always be vertical remove the .navbar-expand-* class.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    

    

Vertical Navbar

Centered navbar

Add the .justify-content-center class to show the center navigation bar

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  

    

    

Centered Navbar

Brand

Add the class .navbar-brand is used for to get a brand of the project name.

Text

To add the text inside an element by adding the class .navbar-brand.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    

    
  
  

Images

Replace the text within the .navbar-brand with a tag.

You can edit and try running this code using Edit & Run option.

    
    
    
      Bootstrap - Navbar
      
      
      
      
      
    
    
      
    
    

Image and text

You can also add some extra utilities to add an image and text at the same time using classes .d-inline-block and .align-text-top on the elements.

You can edit and try running this code using Edit & Run option.

    
    
    
      Bootstrap - Navbar
      
      
      
      
      
    
    
      
    
    

Nav

  • Navbar navigation links are built on the .nav options with their own modifier class and uses the toggler class for responsive styling.

  • The navbar navigation will also expand to occupy as much horizontal space as possible to safely align the navbar content.

  • Add the class .active to the .nav-link to show the current page.

Note that the aria-current attribute should also be added to active .nav links.

You can edit and try running this code using Edit & Run option.

    
    
    
      Bootstrap - Navbar
      
      
      
      
      
    
    
      
    
    

Navbar without list

As navbar uses classes for navigation, list-based approach can be avoided entirely as demonstrated in the following exmaple.

You can edit and try running this code using Edit & Run option.

  


  Bootstrap - Navbar
  
  
  
  
  


  


Navbar with dropdown

To use the dropdowns in navbar add the classes .nav-item and .nav-link as shown in the following example.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Forms

Place various form controls in the navbar by adding the class .form-control.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Children of .navbar now use flex layout and justify-content: space-between by default. Use additional Flex utilities as needed to customize this behavior.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

When your navbar is a complete form or almost form then use the

element as the container.

You can edit and try running this code using Edit & Run option.




  Bootstrap - Navbar
  
  
  
  
  


  


The navbar forms support various buttons. You can use vertical alignment utilities to align different sized elements.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Text

Add the class .navbar-text to adjust vertical alignment and horizontal spacing for strings of text.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Customise with other components and utilities as required as demonstrated below.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Color schemes

New Dark Navbar in v5.3.0 Deprecated .navbar-dark in favor of new data-bs-theme="dark". Include data-bs-theme="dark" to your .navbar to enable component-specific color mode.
New in v5.2.0 - Navbar themes are presently powered with CSS variables and .navbar-light is deprecated. A CSS variable is applied to the .navbar to give it a 'light' look by default and can be overridden in .navbar-dark.
  • By default navbar is a "light navbar" for use with light background colors.

  • Use data-bs-theme="dark" to the parent .navbar class for dark background colors.

  • Net, customize with .bg-* utilities.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    

    

    
  
  

Containers

  • Optionally you wrap the navigation bar in a .container and center it on the page. Note, however, that the inner container is still required.

  • Add a container inside the .navbar to center your fixed or static top navbar content.

You can edit and try running this code using Edit & Run option.




  Bootstrap - Navbar
  
  
  
  
  


  


To modify how wide the content in your navbar is presented use any responsive containers.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Placement

  • Position the navigation bar in a non-static position using the position helper. Choose from pin to top, pin to bottom, fixed to top (scroll page to top and stay there), or stickied to bottom (Scroll until the page reaches the bottom and stop there).

  • Fixed navbars utilize Position: Fixed. This means that it is pulled from the normal flow of the DOM and may need custom CSS (such as padding-top on the ) to avoid overlapping with other elements.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Fixed top

This is acheived using class .fixed-top.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Fixed bottom

This is acheived using class .fixed-bottom.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Sticky top

This is acheived using class .sticky-top.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Sticky bottom

This is acheived using class .sticky-bottom.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Card
    
    
    
    
    
  
  
      

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

Twitter Bootstrap is the most popular front end framework in the recent time. It is sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development. It uses HTML, CSS and Javascript. This tutorial will teach you the basics of Bootstrap Framework using which you can create web projects with ease. The tutorial is divided into sections such as Bootstrap Basic Structure, Bootstrap CSS, Bootstrap Layout Components and Bootstrap Plugins. Each of these sections contain related topics with simple and useful examples.

  • To allow vertical scrolling within the toggleable contents of a collapsed navbar add the classes. navbar-nav-scroll to a .navbar-nav.

  • By default, scrolling kicks has 75vh (75% of the viewport height). By using css property --bs-navbar-height you can override the height.

  • navbar utilizing .navbar-nav-scroll with style="--bs-scroll-height: 100px;", with a few additional margin utilities for optimal spacing.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Responsive behaviors

  • The navbars use the classes .navbar-toggler, .navbar-collapse, and .navbar-expand{-sm|-md|-lg|-xl|-xxl} to find their content collapses behind the button.

  • Add the class.navbar-expandon the navbar for the navbars that are never collapsing. Dont add the class .navbar-expand for navbars that always collapse.

Toggler

By default, navbar togglers are left-aligned, but if they follow a sibling element like a .navbar-brand it will automatically be aligned to the right.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Brand name on the left and toggler on the right

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

Brand name on the right and toggler on the left.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

External content

You need to utilize the collapse plugin to trigger container elements for content that are structurally outside the .navbar. It's easy because our plugin works on target matching of id and data-bs-target.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
    
  
  

Offcanvas

  • Convert expanding and collapsing navbar into an offcanvas drawer with no offcanvas component. To extend both the offcanvas default styles add the classes .navbar-expand-* that creates a dynamic and flexible navigation sidebar.

  • Create an offcanvas navbar that collapses across all breakpoints and skip the .navbar-expand-* class entirely.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

To construct an offcanvas navbar that expands into a normal navbar at the exact breakpoint use .navbar-expand-lg.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  

To avoid text becoming unreadable in a dark navbar, use dark background on the offcanvas content. In the following example

  • Added classes .navbar-dark and .bg-dark to .navbar.

  • Added class .text-bg-dark to .offcanvas.

  • Added class .dropdown-menu-dark to .dropdown-menu

  • And added class .btn-close-white to .btn-close.

You can edit and try running this code using Edit & Run option.

  
  
  
    Bootstrap - Navbar
    
    
    
    
    
  
  
    
  
  
  
Advertisements