TExcelTAD
Home › Bootstrap › Bootstrap Mini Project

Bootstrap Mini Project: A Responsive Admin Dashboard

In this project you'll build a small admin dashboard for an online shop, step by step, using only Bootstrap 5.3 classes and a few lines of JavaScript. By the end it has a top navbar, a sidebar that turns into a slide-in drawer on small screens, statistic cards, an orders table, a quick-add form with validation and a toast notification.

What you'll use

Feature Lessons
Navbar with dark theme Navbar, Dark Mode
Sidebar → offcanvas drawer Offcanvas, Navs, List Groups
Stat cards in a responsive grid Grid, Cards, Badges, Progress Bars
Orders table Tables, Badges, Pagination
Quick-add form Forms, Input Groups, Validation
Feedback Toast
Layout glue Utilities, Flex

Note: The preview frame is as wide as the lesson column — usually below the lg breakpoint (992px). That means you'll see the mobile/tablet version of the dashboard, with a ☰ button that opens the sidebar. Maximise your browser window on a wide screen to see the sidebar permanently on the left. Drag the frame's bottom-right corner down to make it taller; the final dashboard is long.

Step 1 — The top navbar

Start with a dark navbar. The ☰ button opens the sidebar (built in step 2), so it's only shown below lg (d-lg-none).

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-body-tertiary">
  <nav class="navbar bg-dark sticky-top" data-bs-theme="dark">
    <div class="container-fluid">
      <button class="btn btn-outline-light btn-sm d-lg-none me-2" type="button">☰</button>
      <a class="navbar-brand me-auto" href="#">🛍 ShopAdmin</a>
      <span class="navbar-text small d-none d-sm-inline me-3">admin@shop.test</span>
      <span class="rounded-circle bg-primary text-white d-inline-flex align-items-center justify-content-center"
            style="width: 32px; height: 32px;">A</span>
    </div>
  </nav>
  <main class="p-3">Dashboard content goes here.</main>
</body>
</html>

Notice the layout tools: me-auto on the brand pushes the e-mail and avatar to the right, and d-none d-sm-inline hides the e-mail on very small screens.

Step 2 — The sidebar (offcanvas on small screens)

The sidebar uses a responsive offcanvas: .offcanvas-lg makes it a normal column from lg up and a slide-in drawer below. The ☰ button now targets it with data-bs-toggle="offcanvas".

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-body-tertiary">
  <nav class="navbar bg-dark sticky-top" data-bs-theme="dark">
    <div class="container-fluid">
      <button class="btn btn-outline-light btn-sm d-lg-none me-2" type="button"
              data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="sidebar">☰</button>
      <a class="navbar-brand me-auto" href="#">🛍 ShopAdmin</a>
    </div>
  </nav>
  <div class="container-fluid">
    <div class="row">
      <div class="col-lg-2 p-0 border-end bg-body">
        <div class="offcanvas-lg offcanvas-start" tabindex="-1" id="sidebar" aria-labelledby="sidebarLabel" style="--bs-offcanvas-width: 220px;">
          <div class="offcanvas-header">
            <h5 class="offcanvas-title" id="sidebarLabel">Menu</h5>
            <button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#sidebar" aria-label="Close"></button>
          </div>
          <div class="offcanvas-body p-2">
            <nav class="nav nav-pills flex-column w-100">
              <a class="nav-link active" aria-current="page" href="#">📊 Dashboard</a>
              <a class="nav-link" href="#">🧾 Orders</a>
              <a class="nav-link" href="#">📦 Products</a>
              <a class="nav-link" href="#">👥 Customers</a>
              <a class="nav-link" href="#">⚙️ Settings</a>
            </nav>
          </div>
        </div>
      </div>
      <main class="col-lg-10 p-3">Click ☰ to open the sidebar (below lg).</main>
    </div>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Below lg the sidebar column is empty (its content lives in the hidden drawer), so the main column takes the full width.

Step 3 — Stat cards

Four key numbers, shown 1 per row on tiny screens, 2 per row from sm and 4 per row from xl. Each card uses flex utilities to put the icon on the right, and one card includes a slim progress bar.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-body-tertiary p-3">
  <div class="row row-cols-1 row-cols-sm-2 row-cols-xl-4 g-3">
    <div class="col">
      <div class="card border-0 shadow-sm h-100"><div class="card-body d-flex align-items-center">
        <div class="me-auto"><div class="small text-body-secondary">Revenue</div><div class="fs-4 fw-bold">$12,480</div></div>
        <span class="fs-2">💰</span>
      </div></div>
    </div>
    <div class="col">
      <div class="card border-0 shadow-sm h-100"><div class="card-body d-flex align-items-center">
        <div class="me-auto"><div class="small text-body-secondary">Orders</div><div class="fs-4 fw-bold">318 <span class="badge text-bg-success fs-6">+12%</span></div></div>
        <span class="fs-2">🧾</span>
      </div></div>
    </div>
    <div class="col">
      <div class="card border-0 shadow-sm h-100"><div class="card-body d-flex align-items-center">
        <div class="me-auto"><div class="small text-body-secondary">Customers</div><div class="fs-4 fw-bold">1,024</div></div>
        <span class="fs-2">👥</span>
      </div></div>
    </div>
    <div class="col">
      <div class="card border-0 shadow-sm h-100"><div class="card-body">
        <div class="small text-body-secondary">Monthly goal</div>
        <div class="fs-4 fw-bold">72%</div>
        <div class="progress mt-1" role="progressbar" aria-label="Monthly goal" aria-valuenow="72" aria-valuemin="0" aria-valuemax="100" style="height: 6px;">
          <div class="progress-bar bg-warning" style="width: 72%"></div>
        </div>
      </div></div>
    </div>
  </div>
</body>
</html>

Step 4 — The orders table

A responsive table inside a card. Status badges use .text-bg-*; the header row of the card holds the title and a small pagination.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-body-tertiary p-3">
  <div class="card border-0 shadow-sm">
    <div class="card-header bg-body d-flex align-items-center">
      <h6 class="mb-0 me-auto">Recent orders</h6>
      <nav aria-label="Orders pages">
        <ul class="pagination pagination-sm mb-0">
          <li class="page-item active" aria-current="page"><span class="page-link">1</span></li>
          <li class="page-item"><a class="page-link" href="#">2</a></li>
        </ul>
      </nav>
    </div>
    <div class="table-responsive">
      <table class="table table-hover align-middle mb-0 text-nowrap">
        <thead class="table-light"><tr><th>#</th><th>Customer</th><th>Total</th><th>Status</th></tr></thead>
        <tbody>
          <tr><td>1042</td><td>Linh Tran</td><td>$84.00</td><td><span class="badge text-bg-success">Delivered</span></td></tr>
          <tr><td>1041</td><td>Omar Haddad</td><td>$19.50</td><td><span class="badge text-bg-warning">Processing</span></td></tr>
          <tr><td>1040</td><td>Sara Kim</td><td>$210.00</td><td><span class="badge text-bg-info">Shipped</span></td></tr>
          <tr><td>1039</td><td>Ana Silva</td><td>$12.00</td><td><span class="badge text-bg-danger">Cancelled</span></td></tr>
        </tbody>
      </table>
    </div>
  </div>
</body>
</html>

Step 5 — Quick-add form with validation

A compact form to add an order. It uses an input group for the price, a select, Bootstrap validation (novalidate + .was-validated) and logs the new order.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-body-tertiary p-3">
  <div class="card border-0 shadow-sm">
    <div class="card-body">
      <h6 class="card-title">Quick add order</h6>
      <form id="addForm" class="row g-2" novalidate>
        <div class="col-sm-5">
          <input class="form-control" id="customer" placeholder="Customer" aria-label="Customer" required>
          <div class="invalid-feedback">Name required.</div>
        </div>
        <div class="col-sm-3">
          <div class="input-group has-validation">
            <span class="input-group-text">
lt;/span> <input type="number" class="form-control" id="total" min="1" step="0.01" placeholder="0.00" aria-label="Total" required> <div class="invalid-feedback">≥ $1</div> </div> </div> <div class="col-sm-2"> <select class="form-select" id="status" aria-label="Status"> <option>Processing</option><option>Shipped</option><option>Delivered</option> </select> </div> <div class="col-sm-2 d-grid"><button class="btn btn-primary" type="submit">Add</button></div> </form> </div> </div> <script> const form = document.getElementById('addForm'); form.addEventListener('submit', (e) => { e.preventDefault(); form.classList.add('was-validated'); if (!form.checkValidity()) return; const total = Number(document.getElementById('total').value).toFixed(2); console.log('new order:', document.getElementById('customer').value, ' + total, document.getElementById('status').value); form.reset(); form.classList.remove('was-validated'); }); </script> </body> </html>

Step 6 — Putting it all together

Now combine every piece. The form adds a row to the top of the table, updates the order count and shows a toast. A switch in the navbar toggles dark mode.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>ShopAdmin</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-body-tertiary">
  <!-- Navbar -->
  <nav class="navbar bg-dark sticky-top" data-bs-theme="dark">
    <div class="container-fluid">
      <button class="btn btn-outline-light btn-sm d-lg-none me-2" type="button"
              data-bs-toggle="offcanvas" data-bs-target="#sidebar" aria-controls="sidebar">☰</button>
      <a class="navbar-brand me-auto" href="#">🛍 ShopAdmin</a>
      <div class="form-check form-switch text-white mb-0">
        <input class="form-check-input" type="checkbox" role="switch" id="darkMode">
        <label class="form-check-label small" for="darkMode">Dark</label>
      </div>
    </div>
  </nav>

  <div class="container-fluid">
    <div class="row">
      <!-- Sidebar: column from lg, drawer below -->
      <div class="col-lg-2 p-0 border-end bg-body">
        <div class="offcanvas-lg offcanvas-start" tabindex="-1" id="sidebar" aria-labelledby="sidebarLabel" style="--bs-offcanvas-width: 220px;">
          <div class="offcanvas-header">
            <h5 class="offcanvas-title" id="sidebarLabel">Menu</h5>
            <button type="button" class="btn-close" data-bs-dismiss="offcanvas" data-bs-target="#sidebar" aria-label="Close"></button>
          </div>
          <div class="offcanvas-body p-2">
            <nav class="nav nav-pills flex-column w-100">
              <a class="nav-link active" aria-current="page" href="#">📊 Dashboard</a>
              <a class="nav-link" href="#">🧾 Orders <span class="badge text-bg-danger rounded-pill float-end" id="navCount">4</span></a>
              <a class="nav-link" href="#">📦 Products</a>
              <a class="nav-link" href="#">⚙️ Settings</a>
            </nav>
          </div>
        </div>
      </div>

      <!-- Main -->
      <main class="col-lg-10 p-3">
        <h4 class="mb-3">Dashboard</h4>

        <div class="row row-cols-1 row-cols-sm-2 row-cols-xl-4 g-3 mb-3">
          <div class="col"><div class="card border-0 shadow-sm h-100"><div class="card-body d-flex align-items-center">
            <div class="me-auto"><div class="small text-body-secondary">Revenue</div><div class="fs-5 fw-bold" id="revenue">$325.50</div></div><span class="fs-3">💰</span>
          </div></div></div>
          <div class="col"><div class="card border-0 shadow-sm h-100"><div class="card-body d-flex align-items-center">
            <div class="me-auto"><div class="small text-body-secondary">Orders</div><div class="fs-5 fw-bold" id="orders">4</div></div><span class="fs-3">🧾</span>
          </div></div></div>
          <div class="col"><div class="card border-0 shadow-sm h-100"><div class="card-body d-flex align-items-center">
            <div class="me-auto"><div class="small text-body-secondary">Customers</div><div class="fs-5 fw-bold">4</div></div><span class="fs-3">👥</span>
          </div></div></div>
          <div class="col"><div class="card border-0 shadow-sm h-100"><div class="card-body">
            <div class="small text-body-secondary">Goal ($500)</div>
            <div class="progress mt-2" role="progressbar" aria-label="Goal" aria-valuemin="0" aria-valuemax="100" aria-valuenow="65" id="goalTrack" style="height: 8px;">
              <div class="progress-bar bg-warning" id="goalBar" style="width: 65%"></div>
            </div>
          </div></div></div>
        </div>

        <div class="card border-0 shadow-sm mb-3">
          <div class="card-body">
            <h6 class="card-title">Quick add order</h6>
            <form id="addForm" class="row g-2" novalidate>
              <div class="col-sm-5">
                <input class="form-control" id="customer" placeholder="Customer" aria-label="Customer" required>
                <div class="invalid-feedback">Name required.</div>
              </div>
              <div class="col-sm-3">
                <div class="input-group has-validation">
                  <span class="input-group-text">
lt;/span> <input type="number" class="form-control" id="total" min="1" step="0.01" placeholder="0.00" aria-label="Total" required> <div class="invalid-feedback">≥ $1</div> </div> </div> <div class="col-sm-2"> <select class="form-select" id="status" aria-label="Status"><option>Processing</option><option>Shipped</option><option>Delivered</option></select> </div> <div class="col-sm-2 d-grid"><button class="btn btn-primary" type="submit">Add</button></div> </form> </div> </div> <div class="card border-0 shadow-sm"> <div class="card-header bg-body"><h6 class="mb-0">Recent orders</h6></div> <div class="table-responsive"> <table class="table table-hover align-middle mb-0 text-nowrap"> <thead><tr><th>#</th><th>Customer</th><th>Total</th><th>Status</th></tr></thead> <tbody id="rows"> <tr><td>1042</td><td>Linh Tran</td><td>$84.00</td><td><span class="badge text-bg-success">Delivered</span></td></tr> <tr><td>1041</td><td>Omar Haddad</td><td>$19.50</td><td><span class="badge text-bg-warning">Processing</span></td></tr> <tr><td>1040</td><td>Sara Kim</td><td>$210.00</td><td><span class="badge text-bg-info">Shipped</span></td></tr> <tr><td>1039</td><td>Ana Silva</td><td>$12.00</td><td><span class="badge text-bg-danger">Cancelled</span></td></tr> </tbody> </table> </div> </div> </main> </div> </div> <!-- Toast --> <div class="toast-container position-fixed bottom-0 end-0 p-3"> <div class="toast text-bg-success border-0" id="savedToast" role="status" aria-live="polite" aria-atomic="true"> <div class="d-flex"> <div class="toast-body" id="toastText">Order added.</div> <button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button> </div> </div> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> <script> const badgeFor = { Processing: 'warning', Shipped: 'info', Delivered: 'success' }; let nextId = 1043; let orders = 4; let revenue = 325.5; const GOAL = 500; const form = document.getElementById('addForm'); form.addEventListener('submit', (e) => { e.preventDefault(); form.classList.add('was-validated'); if (!form.checkValidity()) return; const name = document.getElementById('customer').value.trim(); const total = Number(document.getElementById('total').value); const status = document.getElementById('status').value; const tr = document.createElement('tr'); tr.className = 'table-primary'; tr.innerHTML = `<td>${nextId}</td><td></td><td>${total.toFixed(2)}</td> <td><span class="badge text-bg-${badgeFor[status]}">${status}</span></td>`; tr.children[1].textContent = name; // textContent: safe for user input document.getElementById('rows').prepend(tr); setTimeout(() => tr.classList.remove('table-primary'), 1500); orders += 1; revenue += total; const pct = Math.min(100, Math.round((revenue / GOAL) * 100)); document.getElementById('orders').textContent = orders; document.getElementById('navCount').textContent = orders; document.getElementById('revenue').textContent = ' + revenue.toFixed(2); document.getElementById('goalBar').style.width = pct + '%'; document.getElementById('goalTrack').setAttribute('aria-valuenow', pct); document.getElementById('toastText').textContent = `Order #${nextId} for ${name} added.`; bootstrap.Toast.getOrCreateInstance(document.getElementById('savedToast')).show(); console.log('order', nextId, name, total.toFixed(2), status, '| goal', pct + '%'); nextId += 1; form.reset(); form.classList.remove('was-validated'); }); document.getElementById('darkMode').addEventListener('change', (e) => { document.documentElement.setAttribute('data-bs-theme', e.target.checked ? 'dark' : 'light'); }); </script> </body> </html>

Try it: submit the empty form to see validation, add a few orders and watch the counters, progress bar and toast, then flip the Dark switch. Below lg, open the sidebar with ☰.

How the pieces fit

Requirement Solution
Sidebar on desktop, drawer on mobile col-lg-2 + .offcanvas-lg
Stats reflow 1 → 2 → 4 per row row-cols-1 row-cols-sm-2 row-cols-xl-4
Equal-height cards h-100 on each card
Wide table on small screens .table-responsive + text-nowrap
Form errors novalidate, checkValidity(), .was-validated, .invalid-feedback
Dark mode for everything data-bs-theme on <html> + theme-aware classes (bg-body, bg-body-tertiary)

Ideas to extend it

  • Add a delete button per row that opens a confirmation modal.
  • Make the sidebar links switch tab panes (Orders, Products, Settings) with data-bs-toggle="pill".
  • Add tooltips to the stat cards explaining each number.
  • Filter the table with a select above it (All / Processing / Shipped / Delivered).
  • Remember the dark-mode choice (on a real site, with localStorage).

Tip: Notice how little custom CSS the dashboard needed — just two inline CSS variables for the drawer width and a few heights. That's the strength of Bootstrap: learn the classes once, and layouts like this take minutes.

Test yourself

Which class makes the sidebar a normal column on large screens but a slide-in drawer below 992px?

  1. .offcanvas
  2. .offcanvas-lg
  3. .collapse-lg
  4. .d-lg-offcanvas

Why does the script set the customer cell with textContent instead of inserting it into innerHTML?

  1. It's faster
  2. It prevents user input from being interpreted as HTML
  3. Bootstrap requires it
  4. innerHTML doesn't work in tables

Which background class keeps the cards' surroundings correct in both light and dark mode?

  1. .bg-light
  2. .bg-white
  3. .bg-body-tertiary
  4. .bg-gray-100