In bootstrap 5, Nav Bar is used to connect and link all the web pages related to a website and a user can move between pages easily. Navigation bar is a very important component of a website that contains a brand logo, page names and their links, and a search box according to user requirements.
This article give you a detail knowledge about
- Creating a navbar
- Navbar with dropdown menu
- Navbar with Inline Form
- Collapsible Navbar
- Changing Navbar Colors
How to create a navbar
To create a navbar use, .navbar class and to align the menu in a row use .navbar-expand-xxl/lg/md/sm. In order to choose between light or dark mood use .navbar-light/dark and to give a background color to a navbar use .bg-light.
<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image1-48.png" data-lazy- height="160" src="data:image/svg xml,” width=”744″>
Code:
<div class=“container mb-5”>
<h3 class=“py-3 text-center”>Bootstrap 5 Navbar</h3>
<div class=“row py-3”>
<div class=“col”>
<nav class=“navbar navbar-expand-md navbar-light bg-light”>
<a href=“#” class=“navbar-brand”>Cubator 1ne</a>
<ul class=“navbar-nav”>
<li class=“nav-item”><a href=“” class=“nav-link”>Home</a></li>
<li class=“nav-item”><a href=“” class=“nav-link”>About Us</a></li>
<li class=“nav-item”><a href=“” class=“nav-link”>Gallery</a></li>
<li class=“nav-item”><a href=“” class=“nav-link”>Contact Us</a></li>
</ul>
</nav>
</div>
</div>
</div>
</div>
This is how you create a navbar in bootstrap 5.
Navbar with dropdown menu
To create a navbar with dropdown menu use .dropdown class with .nav-item class in
<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image3-43.png" data-lazy- height="264" src="data:image/svg xml,” width=”753″>
Code
<nav class=“navbar navbar-expand-md navbar-light bg-light”>
<a href=“#” class=“navbar-brand”>Cubator 1ne</a>
<ul class=“navbar-nav mr-auto”>
<li class=“nav-item”><a href=“” class=“nav-link”>Home</a></li>
<li class=“nav-item”><a href=“” class=“nav-link”>About Us</a></li>
<li class=“nav-item dropdown”>
<a href=“” class=“nav-link dropdown-toggle” data-bs-toggle=“dropdown”>Gallery</a>
<div class=“dropdown-menu”>
<a href=“” class=“dropdown-item”>Tour Pics</a>
<a href=“” class=“dropdown-item”>Annual Dinner</a>
<a href=“” class=“dropdown-item”>Prize Distribution</a>
</div>
</li>
<li class=“nav-item”><a href=“” class=“nav-link”>Contact Us</a></li>
</ul>
</nav>
This is how a navbar with a dropdown menu is created.
Navbar with inline form
To create a navbar with inline form, use tag with the class .inline-form and wrap it around an tag with the class .form-control and add a button using a tag with the class .btn,btn-success, right after the closing tag.
<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image2-43.png" data-lazy- height="185" src="data:image/svg xml,” width=”749″>
<nav class=“navbar navbar-expand-md navbar-light bg-light”>
<a href=“#” class=“navbar-brand”>Cubator 1ne</a>
<ul class=“navbar-nav”>
<li class=“nav-item”><a href=“” class=“nav-link”>Home</a></li>
<li class=“nav-item”><a href=“” class=“nav-link”>About</a></li>
<li class=“nav-item dropdown”>
<a href=“” class=“nav-link dropdown-toggle” data-bs-toggle=“dropdown”>Gallery</a>
<div class=“dropdown-menu”>
<a href=“” class=“dropdown-item”>Tour Pics</a>
<a href=“” class=“dropdown-item”>Annual Dinner</a>
<a href=“” class=“dropdown-item”>Prize Distribution</a>
</div>
</li>
<li class=“nav-item”><a href=“” class=“nav-link”>Contact</a></li>
</ul>
<form class=“form-inline d-flex flex-nowrap”>
<input type=“search” class=“form-control” placeholder=“search”>
<button class=“btn btn-outline-success”>Search</button>
</form>
</nav>
This is how you create a navbar with inline form.
Collapsible Navbar
To create a collapsible navbar, use a
- and
<img alt="" data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/image4-1.gif" height="303" src="data:image/svg xml,” width=”747″>
<nav class=“navbar navbar-expand-md navbar-light bg-light”>
<a href=“#” class=“navbar-brand”>Cubator 1ne</a>
<button class=“navbar-toggler” data-bs-toggle=“collapse” data-bs-target=“#mnav”>
<span class=“navbar-toggler-icon”></span>
</button>
<div class=“collapse navbar-collapse” id=“mnav”>
<ul class=“navbar-nav”>
<li class=“nav-item”><a href=“” class=“nav-link”>Home</a></li>
<li class=“nav-item”><a href=“” class=“nav-link”>About</a></li>
<li class=“nav-item dropdown”>
<a href=“” class=“nav-link dropdown-toggle” data-bs-toggle=“dropdown”>Gallery</a>
<div class=“dropdown-menu”>
<a href=“” class=“dropdown-item”>Tour Pics</a>
<a href=“” class=“dropdown-item”>Annual Dinner</a>
<a href=“” class=“dropdown-item”>Prize Distribution</a>
</div>
</li>
<li class=“nav-item”><a href=“” class=“nav-link”>Contact</a></li>
</ul>
<form class=“form-inline d-flex flex-nowrap”>
<input type=“search” class=“form-control” placeholder=“search”>
<button class=“btn btn-outline-success”>Search</button>
</form>
</div>
</nav>
This is how you create a collapsible navbar.
Change Navbar Color
To change the color of the navbar use following classes
- bg-light
- bg-primary
- bg-success
- bg-warning
- bg-info
- bg-danger
or use inline tag with background:#color; attribute.
Conclusion
To create a navbar use, .navbar, .navbar-expand-xxl/lg/md/sm, .navbar-light/dark, bg-light/primary/success/warning/info/danger class with
About the author
<img data-del="avatar" data-lazy-src="https://kirelos.com/wp-content/uploads/2022/04/echo/7011409B3A384F43A8417D1DAC68D179-150×150.jpg625e23ed7d938.jpg" height="112" src="data:image/svg xml,” width=”112″>
Shehroz Azam
A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.