Nearby lessons
29 of 39π BS5 Offcanvas
π What Is Bootstrap 5 Offcanvas?
Offcanvas is a panel that slides in from an edge (sidebar, cart, filters). Use .offcanvas with a position class, an id, and .offcanvas-header / .offcanvas-body. Trigger: data-bs-toggle="offcanvas" and data-bs-target="#offcanvasId". Requires Bootstrapβs JavaScript.
π Offcanvas Structure (.offcanvas, .offcanvas-header, .offcanvas-body)
.offcanvas β panel wrapper. .offcanvas-header β top bar with .offcanvas-title and .btn-close (data-bs-dismiss="offcanvas"). .offcanvas-body β main content. Give the offcanvas an id for the trigger.
π Position (.offcanvas-start, .offcanvas-end, .offcanvas-top, .offcanvas-bottom)
.offcanvas-start β slides from the left. .offcanvas-end β from the right. .offcanvas-top β from the top. .offcanvas-bottom β from the bottom. Add one to the same element as .offcanvas.
β Offcanvas Best Practices
- Use data-bs-toggle="offcanvas" and data-bs-target="#id" on the trigger.
- Use .offcanvas-start or .offcanvas-end for side panels.
- Close button: .btn-close with data-bs-dismiss="offcanvas".
π§ Test Your Knowledge
3 QuestionsProgress: 0 / 3
Keep Going!BS5 Utilities