Frontend & Architecture6 min read

Building Responsive Admin Dashboards with Bootstrap 5

Md Shahed Alam
Md Shahed Alam
January 28, 2025
Building Responsive Admin Dashboards with Bootstrap 5

Admin dashboards are something almost every developer builds eventually. Bootstrap 5 makes it straightforward — here is a practical guide with real code.

Project setup

Include Bootstrap 5 via CDN or install via npm:

npm install bootstrap @popperjs/core

Import it in your main JavaScript file:

import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap';

The basic layout

A typical admin dashboard has a fixed sidebar, a top navbar, and a main content area. Bootstrap's grid and flex utilities make this easy:

<div class="d-flex" id="wrapper">
  <div id="sidebar" class="bg-dark text-white p-3" style="width: 250px; min-height: 100vh;">
    <h5 class="mb-4">Admin Panel</h5>
    <ul class="nav flex-column">
      <li class="nav-item"><a href="#" class="nav-link text-white">Dashboard</a></li>
      <li class="nav-item"><a href="#" class="nav-link text-white">Users</a></li>
      <li class="nav-item"><a href="#" class="nav-link text-white">Reports</a></li>
    </ul>
  </div>
  <div id="page-content-wrapper" class="flex-grow-1">
    <nav class="navbar navbar-expand-lg navbar-light bg-light border-bottom px-4">
      <!-- top nav content -->
    </nav>
    <div class="container-fluid p-4">
      <!-- page content -->
    </div>
  </div>
</div>

Stats cards

The iconic dashboard metrics at the top:

<div class="row g-3 mb-4">
  <div class="col-md-3">
    <div class="card border-0 shadow-sm">
      <div class="card-body">
        <h6 class="text-muted">Total Users</h6>
        <h2 class="fw-bold">1,234</h2>
        <small class="text-success">↑ 12% from last month</small>
      </div>
    </div>
  </div>
</div>

Responsive sidebar toggle

For mobile, toggle the sidebar with a button and use Bootstrap's collapse or a simple CSS class toggle:

document.getElementById('sidebarToggle').addEventListener('click', () => {
  document.getElementById('sidebar').classList.toggle('d-none');
});

Bootstrap 5 removes the jQuery dependency, so plain JavaScript is all you need. The result is a clean, responsive admin interface that works well across devices.

FrontendArchitecture

Ready to build something great?

Let's talk about your project. We will give you honest advice, a clear plan, and a fair price. No pressure, no sales pitch.