Offcanvas: Slide-in Panels
What is an Offcanvas?
An offcanvas is a panel that slides in from the edge of the screen. It is perfect for mobile menus, shopping carts and filters.
Basic Example
html
<button class="btn btn-primary" data-bs-toggle="offcanvas" data-bs-target="#sideMenu">
Open Menu
</button>
<div class="offcanvas offcanvas-start" tabindex="-1" id="sideMenu" aria-labelledby="sideMenuLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="sideMenuLabel">Menu</h5>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="list-unstyled">
<li><a href="#">Home</a></li>
<li><a href="#">Courses</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
Placement
| Class | Slides From |
|---|---|
offcanvas-start | Left |
offcanvas-end | Right |
offcanvas-top | Top |
offcanvas-bottom | Bottom |
Backdrop and Scrolling
html
<!-- Keep scrolling on the page and remove the dark backdrop -->
<div class="offcanvas offcanvas-start" data-bs-scroll="true" data-bs-backdrop="false">...</div>
<!-- Prevent closing on outside click -->
<div class="offcanvas offcanvas-end" data-bs-backdrop="static">...</div>
Responsive Offcanvas
With offcanvas-lg the panel behaves like a normal element on large screens and as a slide-in panel on smaller screens. This is how many sidebars work.
html
<div class="offcanvas-lg offcanvas-start" id="responsiveSidebar">
<div class="offcanvas-header">...</div>
<div class="offcanvas-body">Visible always on large screens.</div>
</div>
Result
A panel slides in from the left with a dark backdrop. Clicking the X or the backdrop slides it away.
Modal or offcanvas? Use a modal for focused questions or forms in the center, and an offcanvas for navigation, filters and carts at the side.
Conclusion
Offcanvas is a modern pattern for mobile-friendly menus. It works like a modal but slides in from an edge.
Quick Summary: offcanvas + offcanvas-start/end/top/bottom, open with data-bs-toggle="offcanvas", close with data-bs-dismiss.

