Foresite Design Logo - Responsive Website Design

Foresite Design Editorial Team · Updated for 2026

Foresite Design Logo - Responsive Website Design

How to create a navbar using Bootstrap 5 and Bootstrap-icons

In this tutorial, you'll learn how to build a modern, fully responsive navigation bar using Bootstrap 5 and Bootstrap Icons — following current best practices for accessibility, performance, and maintainability.

Step 1: Setup HTML Structure
Start by setting up the basic HTML structure for your webpage.
Create an HTML file and include the following code:

  
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap 5 navbar with icons tutorial</title>
<!-- Add Bootstrap CSS Link -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!-- Navbar goes here -->  
<!-- Content goes here -->
<!-- Bootstrap Bundle JS Scripts -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
  
 

Step 2: Create the Navbar
Inside the <body> of your HTML file, add the following code to create the Bootstrap navbar:

  
<nav class="navbar navbar-expand-lg">
<div class="container">
<a class="navbar-brand" href="/">Your Brand</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="
navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarNav"> <ul class="navbar-nav ms-auto"> <li class="nav-item"> <a class="nav-link" href="#">Home</a> </li> <li class="nav-item"> <a class="nav-link" href="#">About</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Blog</a> </li> <li class="nav-item"> <a class="nav-link" href="#">Contact</a> </li> </ul> </div> </div> </nav>

This code creates a responsive navbar with a brand logo and navigation links. We've also included a toggle button for smaller screens.

Step 3: Add Bootstrap Icons
To add Bootstrap icons to your navbar, you can use Bootstrap Icon's CDN. Include the following line inside the <head> section of your HTML file:

    
      <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css" rel="stylesheet">
    
  

Now, you can add icons to your navbar. For example, add icons before or after "Home," "About," "Blog," and "Contact" Nav links:
me-1 replaces manual spacing (Bootstrap-native)

    
<li class="nav-item">
<a class="nav-link" href="#">Home <i class="bi bi-house-door me-1" aria-hidden="true"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About <i class="bi bi-person me-1" aria-hidden="true"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Blog <i class="bi bi-journal-text me-1" aria-hidden="true"></i></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact <i class="bi bi-envelope me-1" aria-hidden="true"></i></a>
</li>
    
  

Step 4: Customize Styling
You can customize the styling of the navbar and icons using your own CSS or by overriding Bootstrap's CSS classes.
Experiment with the Bootstrap classes and your own styles to achieve the desired look for your Bootstrap navbar.

    
/* Custom Styles for Navbar */
.navbar {
    background-color: #282828; /* Change to your desired background color */
}
.navbar-brand,
.navbar-nav .nav-link {
    color: #fff; /* Text color for the brand/logo */
    font-weight: bold;
}
.navbar-brand:hover{
   color: #f1c40f;
}
.navbar-toggler {
  border-color: rgba(255,255,255,0.4);
}
.navbar-nav .nav-link:hover {
    color: #f1c40f; /* Hover color for navigation links */
}
    
  

You can place this CSS code in a separate CSS file (e.g., style.css) and include it in your HTML file by adding the following line inside the <head> section:

            <link rel="stylesheet" href="style.css">
          

This CSS code provides some basic styling for the navbar, including background colors, text colors, and spacing.
You can further customize these styles to match your website's design preferences.

That's it! You now have a working Bootstrap 5 navbar with Bootstrap icons for your website.
Don't forget to add your content below the navbar in the "Content goes here" section of your HTML file.

Common Bootstrap Navbar Mistakes to Avoid

  • Using deprecated classes: Bootstrap 5 no longer supports ml-* or mr-*. Always use ms-* and me-*.
  • Forgetting the Bootstrap JS bundle: Dropdowns and navbar toggles will not function without bootstrap.bundle.min.js.
  • Incorrect icon placement: Icons should be placed inside anchor tags and marked as decorative using aria-hidden="true".
  • Overriding Bootstrap core styles incorrectly: Avoid changing internal SVG styles such as .navbar-toggler-icon. Use utility classes or wrapper elements instead.
  • Not testing mobile behaviour: Always test the navbar collapse and dropdown interactions on real mobile devices.

Frequently Asked Questions

Yes. Bootstrap 5 is actively maintained, jQuery-free, and widely used for building responsive, accessible user interfaces in modern web projects.

No. Bootstrap Icons are delivered via CSS and SVG fonts and do not require JavaScript. They can be styled using standard Bootstrap utility classes.

Bootstrap 5 uses logical CSS properties. ms-auto means “margin start” and replaces ml-auto to support both left-to-right and right-to-left layouts.

Yes. This navbar structure works in WordPress, Laravel, static sites, and headless CMS platforms. Ensure Bootstrap assets are properly enqueued for interactive features.
Previous page