🧱 Bootstrap 5 Sidebars Demo – Responsive Layouts for Navigation & Tools
🧲 Introduction – What Are Sidebars in Bootstrap 5?
Sidebars are vertical panels often used for site navigation, filters, profile links, or admin controls. Bootstrap 5 allows you to build responsive sidebars using the grid system, flexbox utilities, and visibility classes—without any extra JavaScript.
🎯 In this guide, you’ll learn:
- How to create fixed and collapsible sidebars with
.col-*
and.d-flex
- Control sidebar behavior on mobile using Bootstrap’s responsive utilities
- Use
.sticky-top
for persistent sidebar visibility - Build sidebar menus using
.nav
,.list-group
, or vertical.btn
stacks
✅ Example 1 – Basic Sidebar with Grid Layout
<div class="container-fluid">
<div class="row">
<nav class="col-md-3 col-lg-2 d-md-block bg-light sidebar p-3">
<h5>Sidebar Menu</h5>
<ul class="nav flex-column">
<li class="nav-item"><a href="#" class="nav-link">Dashboard</a></li>
<li class="nav-item"><a href="#" class="nav-link">Orders</a></li>
<li class="nav-item"><a href="#" class="nav-link">Products</a></li>
</ul>
</nav>
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<h1>Main Content Area</h1>
<p>This section contains the main content beside the sidebar.</p>
</main>
</div>
</div>
Class | Description |
---|---|
.col-md-3 , .col-lg-2 | Sets sidebar width responsively |
.sidebar , .p-3 | Adds spacing and styling to the sidebar |
.nav , .flex-column | Creates vertical navigation menu |
📌 Great for dashboards, blog layouts, or CMS interfaces.
✅ Example 2 – Sticky Sidebar with Scrollable Content
<div class="container-fluid">
<div class="row">
<nav class="col-md-3 col-lg-2 d-none d-md-block bg-light p-3 sticky-top h-100">
<h5>Sticky Sidebar</h5>
<ul class="list-group">
<li class="list-group-item">Overview</li>
<li class="list-group-item">Reports</li>
<li class="list-group-item">Analytics</li>
</ul>
</nav>
<main class="col-md-9 ms-sm-auto col-lg-10 px-md-4">
<p>Scroll this area to see sidebar staying fixed in position.</p>
<div style="height: 1500px;"></div>
</main>
</div>
</div>
Class | Description |
---|---|
.sticky-top | Makes the sidebar stick to top when scrolling |
.h-100 | Full height sidebar container |
.d-none d-md-block | Hides sidebar on small screens |
📌 Use sticky sidebars for reports, filters, or navigation that should remain visible.
✅ Example 3 – Collapsible Sidebar for Small Screens
<button class="btn btn-primary d-md-none" data-bs-toggle="collapse" data-bs-target="#mobileSidebar">
Toggle Sidebar
</button>
<div class="collapse d-md-block" id="mobileSidebar">
<div class="bg-light p-3">
<h5>Mobile Sidebar</h5>
<ul class="nav flex-column">
<li class="nav-item"><a href="#" class="nav-link">Home</a></li>
<li class="nav-item"><a href="#" class="nav-link">Profile</a></li>
</ul>
</div>
</div>
Attribute / Class | Function |
---|---|
data-bs-toggle="collapse" | Toggles visibility on click |
.collapse , .d-md-block | Collapses only on small screens |
#mobileSidebar | Target ID for collapsing element |
📌 Responsive sidebar toggles are useful for mobile menus or app-style layouts.
✅ Example 4 – Sidebar with Button Stack
<div class="bg-light p-3">
<div class="btn-group-vertical w-100">
<button type="button" class="btn btn-outline-primary">Overview</button>
<button type="button" class="btn btn-outline-secondary">Settings</button>
<button type="button" class="btn btn-outline-danger">Logout</button>
</div>
</div>
Class | Description |
---|---|
.btn-group-vertical | Stacks buttons vertically |
.w-100 | Makes buttons full width |
.btn-outline-* | Adds styled outline variants |
📌 Use vertical buttons in sidebars for quick actions or admin tools.
📘 Bootstrap Sidebar Utility Reference
Element | Class / Utility Used | Purpose |
---|---|---|
Sidebar Width | .col-md-3 , .col-lg-2 | Set fixed sidebar width |
Visibility Toggle | .collapse , .d-md-block | Mobile toggle support |
Sticky Behavior | .sticky-top , .h-100 | Keeps sidebar in view while scrolling |
Navigation Menu | .nav , .list-group , .btn-group-vertical | Sidebar link styles |
Button Styling | .btn , .btn-outline-* , .w-100 | Vertical full-width actions |
🛠️ Best Practices for Bootstrap Sidebars
Tip | Why It’s Useful |
---|---|
Combine .d-flex with .vh-100 | Ensures full-height flexible sidebar layouts |
Use .sticky-top for persistent nav | Helps users access links while scrolling |
Add collapse for mobile viewports | Keeps layout clean and focused on small screens |
Use .w-100 with button groups | Ensures action buttons align consistently |
Hide sidebars when unnecessary | Improve UX by avoiding clutter |
📌 Summary – Recap & Next Steps
With Bootstrap 5, creating responsive and functional sidebars is straightforward. Whether fixed, collapsible, or sticky, sidebars enhance navigation and user control in your layout.
🔍 Key Takeaways:
- Use grid (
.col-*
) or flexbox (.d-flex
) to structure sidebars - Add
.sticky-top
for fixed scrolling behavior - Collapse sidebars on mobile using
.collapse
+data-bs-toggle
- Use
.nav
,.list-group
, or button stacks for content
⚙️ Ideal for dashboards, admin panels, blogs, product filters, and mobile web apps.
❓ FAQs – Bootstrap 5 Sidebars
❓ How do I make the sidebar fixed to the left?
✅ Use .position-fixed start-0
along with a set width
(e.g., style="width:250px;"
).
❓ Can sidebars be collapsed by default on mobile?
✅ Yes. Wrap sidebar in .collapse
and trigger with a toggle button.
❓ Are sidebars accessible with screen readers?
✅ Add aria-label
, role="navigation"
or role="complementary"
for accessibility.
❓ Can I add icons to sidebar menus?
✅ Yes. Use Bootstrap Icons or Font Awesome inside <a>
or <button>
elements.
Share Now :