How to create a Responsive Bootstrap 5 Sidebar


By Amarachi Iheanacho

Technical Writer

Sometimes, there are pieces of information in a column to the right or left of the main content in a website layout. This column is known as a sidebar.

Bootstrap 5 Sidebars are a User Interface element ( usually a column to the left ) containing supplementary information, like navigation links or ads.

Table Of Contents

  • What are we building?
  • Prerequisites
  • What is Contrast?
  • Creating our Bootstrap 5 Sidebar
  • Conclusion
  • Resources

What we are building

In this article, we are going to walk through building a Bootstrap sidebar with Contrast. Like the image we have below:

Bootstrap 5 Sidebar


To make the most of this article, it is important that you have the following:

  • A basic understanding of HTML.
  • A basic understanding of CSS.
  • A basic understanding of JavaScript

Understanding what Contrast is

Contrast or Contrast Design Bootstrap is an elegant bootstrap UI kit featuring over 2000+ essential components. Contrast helps simplify the web development process and can be integrated with any project to build mobile-first, responsive, and elegant websites and web apps.

Adding the Contrast library CDN

We will be using the Contrast library to build out our Bootstrap 5 Sidebar. To do that we start by including the library in our project using the Bootstrap CDN.

We include the CSS CDN responsible for the Bootstrap styling in the <head> in our HTML file.

1<link rel="stylesheet" href=""/>
2<link rel="stylesheet" href=""/>

After including the CSS CDN links, we then include the JavaScript CDN responsible for creating dynamic components at the bottom of our project. We do this because we want our components before adding the functionality.

1<script src=""></script>
2<script src=""></script>
3<script src=""></script>

After adding the CDNs our HTML file should look like this

1<!DOCTYPE html>
2<html lang="en">
4 <meta charset="UTF-8">
5 <meta http-equiv="X-UA-Compatible" content="IE=edge">
6 <meta name="viewport" content="width=device-width, initial-scale=1.0">
7 <link rel="stylesheet" href=""/>
8 <link rel="stylesheet" href=""/>
9 <title>Document</title>
14<script src=""></script>
15<script src=""></script>
16<script src=""></script>

Creating our Bootstrap Sidebar

With Contrast Bootstrap we can create 2 kinds of sidebars

  • Default Sidebar
  • Multilevel Advanced Sidebar

Default Sidebar

1<div class="mx-auto r-w">
2 <div class="container">
3 <div class="app" style="display: flex; height: 100%; position: absolute">
4 <div class="sidebar bg-dark text-white" id="sidebar-showcase" role="cdb-sidebar">
5 <div class="sidebar-container">
6 <div class="sidebar-header text-center">
7 <a class="sidebar-toggler"><i class="fa fa-bars"></i></a>
8 <a class="sidebar-brand">Contrast</a>
9 </div>
11 <div class="sidebar-nav">
12 <div class="sidenav">
13 <a class="sidebar-item">
14 <i class="fa fa-th-large sidebar-icon"></i>
15 <span>Dashboard</span>
16 </a>
17 <a class="sidebar-item">
18 <i class="fa fa-sticky-note sidebar-icon"></i>
19 <span>Components</span>
20 </a>
21 </div>
23 <div class="sidenav">
24 <div class="sidebar-dropdown">
25 <div
26 class="sidebar-item"
27 data-toggle="collapse"
28 data-target="#collapseOne"
29 aria-expanded="true"
30 aria-controls="collapseOne"
31 >
32 <i class="fa fa-th sidebar-icon"></i>
33 <span>Sidemenu</span>
34 <i class="fa fa-angle-right arrow-wrapper ml-auto"></i>
35 </div>
37 </div>
38 <div class="sidebar-dropdown">
39 <div
40 class="sidebar-item"
41 data-toggle="collapse"
42 data-target="#collapseTwo"
43 aria-expanded="true"
44 aria-controls="collapseTwo"
45 >
46 <i class="fa fa-book sidebar-icon"></i>
47 <span>Sidemenu 2</span>
48 <i class="fa fa-angle-right arrow-wrapper ml-auto"></i>
49 </div>
51 </div>
52 </div>
53 </div>
55 <div class="sidebar-footer">Sidebar Footer</div>
56 </div>
57 </div>
58 </div>
59 </div>
60 </div>

Adding JavaScript for interaction

Using JavaScript enables your project to be dynamic and allows users to interact with your components and web pages.

2 const sidebar = document.querySelector('.sidebar');
3 new CDB.Sidebar(sidebar);
6<script src="../build/cdbbootstrap.js"></script>

In the code block above, we use the querySelector document object to select the sidebar using the sidebar class we gave it sidebar.

We then create a new sidebar instance from the Sidebar method we get from CDB.

Lastly, we link our project to the JavaScript file we get from the Contrast Bootstrap.

With that, we have created our dynamic Bootstrap 5 Sidebar using the Contrast UI library.

Bootstrap 5 Sidebar.

Multitlevel Sidebar

With the Contrast Multilvel Sidebar, we are able to create submenus in our sidebars, this submenus refer to menus located inside a menu.

1<div class="app" style="display: flex; height: 100%; position: absolute">
2 <div class="sidebar bg-dark text-white" id="sidebar-showcase" role="cdb-sidebar">
3 <div class="sidebar-container">
4 <div class="sidebar-header text-center">
5 <a class="sidebar-toggler"><i class="fa fa-bars"></i></a>
6 <a class="sidebar-brand">Contrast</a>
7 </div>
9 <div class="sidebar-nav">
10 <div class="sidenav">
11 <a class="sidebar-item">
12 <i class="fa fa-th-large sidebar-icon"></i>
13 <span>Dashboard</span>
14 </a>
15 <a class="sidebar-item">
16 <i class="fa fa-sticky-note sidebar-icon"></i>
17 <span>Components</span>
18 </a>
19 </div>
21 <div class="sidenav">
22 <div class="sidebar-dropdown">
23 <div
24 class="sidebar-item"
25 data-toggle="collapse"
26 data-target="#collapseOne"
27 aria-expanded="true"
28 aria-controls="collapseOne"
29 >
30 <i class="fa fa-th sidebar-icon"></i>
31 <span>Sidemenu</span>
32 <i class="fa fa-angle-right arrow-wrapper ml-auto"></i>
33 </div>
34 <div class="sidebar-sub-menu collapse bg-dark" id="collapseOne">
35 <a class="sub-menu-item">Submenu 1</a>
36 <a class="sub-menu-item">Submenu 2</a>
37 <a class="sub-menu-item">Submenu 3</a>
38 </div>
39 </div>
40 <div class="sidebar-dropdown">
41 <div
42 class="sidebar-item"
43 data-toggle="collapse"
44 data-target="#collapseTwo"
45 aria-expanded="true"
46 aria-controls="collapseTwo"
47 >
48 <i class="fa fa-book sidebar-icon"></i>
49 <span>Sidemenu 2</span>
50 <i class="fa fa-angle-right arrow-wrapper ml-auto"></i>
51 </div>
52 <div class="sidebar-sub-menu collapse bg-dark" id="collapseTwo">
53 <a class="sub-menu-item">Submenu 1</a>
54 <a class="sub-menu-item">Submenu 2</a>
55 <a class="sub-menu-item">Submenu 3</a>
56 </div>
57 </div>
58 </div>
59 </div>
61 <div class="sidebar-footer">Sidebar Footer</div>
62 </div>
63 </div>

Adding JavaScript for interaction

2 const sidebarNav = document.querySelector('#sidebar-nav');
3 new CDB.Sidebar(sidebarNav);
6 const sidebarShow = document.querySelector('#sidebar-showcase');
7 new CDB.Sidebar(sidebarShow);

After this we have a sidebarthat looks a lot like

Bootstrap 5 Sidebar


This article discussed what Bootstrap 5 Sidebar is, why you would use the Bootstrap Sidebar in your project, and how to create one.


You may find the following resources helpful.

Create Stunning websites and web apps

Trying to build out all user interfaces and components for your website or web app from scratch can become a very tedious task. A huge reason why we created Contrast Bootstrap to help reduce the amount of time we spend doing that, so we can focus on building some other aspects of the project. Contrast Bootstrap PRO consists of a UI Kit featuring over 10000+ component variants. Together with a template of 5 admin dashboards and 23+ additional multipurpose pages template for building almost any type of website or web app. You can view a demo and learn more about Contrast by clicking here.Try contrast pro


Contrast Bootstrap PRO was built using the most popular CSS framework Bootstrap to help build your next landing, admin SAAS, prelaunch etc project with a clean, prebuilt and well documented template and UI components.Learn more about Contrast

Related Posts