A beautiful responsive sidebar navigation built for Bootstrap 5

Author: harshitjain-hj
Official Page: Go to website
Last Update: August 5, 2021
License: MIT

About

It is an extension built for Bootstrap 5 that will help you in creating a beautiful responsive sidebar navigation bar easily in your new or an existing project which is created using Bootstrap 5.

You might be interested in:

How can I use it?

There are four simple steps to implement bootstrap navigation bar in your page.

1) Write the HTML elements for the navigation as following:

    <!-- Side-Nav -->
    <div class="side-navbar active-nav d-flex justify-content-between flex-wrap flex-column" id="sidebar">
      <ul class="nav flex-column text-white w-100">
        <a href="#" class="nav-link h3 text-white my-2">
          Welcome </br>to Lipku.com
        </a>
        <li href="#" class="nav-link">
          <i class="bx bxs-dashboard"></i>
          <span class="mx-2">Home</span>
        </li>
        <li href="#" class="nav-link">
          <i class="bx bx-user-check"></i>
          <span class="mx-2">Profile</span>
        </li>
        <li href="#" class="nav-link">
          <i class="bx bx-conversation"></i>
          <span class="mx-2">Contact</span>
        </li>
      </ul>

      <span href="#" class="nav-link h4 w-100 mb-5">
        <a href=""><i class="bx bxl-instagram-alt text-white"></i></a>
        <a href=""><i class="bx bxl-twitter px-2 text-white"></i></a>
        <a href=""><i class="bx bxl-facebook text-white"></i></a>
      </span>
    </div>

2) Now add toggle button HTML (It’ll be a button, where user will click to show/hide the menu).

    <!-- Main Wrapper -->
    <div class="p-1 my-container active-cont">
      <!-- Top Nav -->
      <nav class="navbar top-navbar navbar-light bg-light px-5">
        <a class="btn border-0" id="menu-btn"><i class="bx bx-menu"></i></a>
      </nav>
      <!--End Top Nav -->
      <h3 class="text-dark p-3">RESPONSIVE SIDEBAR NAV 💻 📱 
      </h3>
      <p class="px-3">Responsive navigation sidebar built using <a class="text-dark" href="https://getbootstrap.com/">Bootstrap 5</a>.</p>
    </div>

3) Now add some CSS style, as:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  background-color: #fff;
}

.side-navbar {
  width: 180px;
  height: 100%;
  position: fixed;
  margin-left: -300px;
  background-color: #100901;
  transition: 0.5s;
}

.nav-link:active,
.nav-link:focus,
.nav-link:hover {
  background-color: #ffffff26;
}

.my-container {
  transition: 0.4s;
}

.active-nav {
  margin-left: 0;
}

/* for main section */
.active-cont {
  margin-left: 180px;
}

#menu-btn {
  background-color: #100901;
  color: #fff;
  margin-left: -62px;
}

.my-container input {
  border-radius: 2rem;
  padding: 2px 20px;
}

4) Now Add few lines of JavaScript code that is required to make responsive sidebar menu functional.

<script>
      var menu_btn = document.querySelector("#menu-btn");
      var sidebar = document.querySelector("#sidebar");
      var container = document.querySelector(".my-container");
      menu_btn.addEventListener("click", () => {
        sidebar.classList.toggle("active-nav");
        container.classList.toggle("active-cont");
      });
    </script>