Skip to content

Offcanvas Shopping Cart

Bootstrap 5 offcanvas cart drawer with quantity steppers, remove buttons, free-shipping progress, live totals and an empty state.

Also known as: slide in cart drawer, side cart, mini cart sidebar, shopping cart sidebar

Offcanvas Shopping Cart live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A Bootstrap 5 offcanvas shopping cart that slides in from the right with line items, quantity steppers, remove buttons, a free-shipping progress meter and an order summary. A small product grid with "Add to cart" buttons is included so the drawer can be tried end to end; drop it into any online store header.

How it works

The root .oc-shop holds a header with the .oc-cart-btn toggle (data-bs-toggle="offcanvas", data-bs-target="#oc-cart") and its .oc-badge counter, the product grid, and the aside.offcanvas.offcanvas-end.oc-drawer. The drawer contains the .oc-ship meter (a Bootstrap .progress), the .oc-items list of li.oc-item elements, the .oc-empty message and the .oc-summary footer with subtotal, shipping, total and the .oc-checkout button. Each item stores its unit price in data-price and its identity in data-id.

The drawer starts with the show class, so Bootstrap opens it on page load. Opening, closing, the backdrop, the focus trap and Escape handling all come from Bootstrap's Offcanvas plugin.

The script runs on DOMContentLoaded for every .oc-shop. A single render() function recalculates line prices, the item count in the badge and title, subtotal, shipping and total, formats them with Intl.NumberFormat, and updates the shipping bar width and aria-valuenow. A delegated click listener on .oc-items handles data-oc-step buttons (clamped between 1 and MAX_QTY) and data-oc-remove. Buttons with data-oc-add either raise the quantity of an existing item or clone .oc-item-template, then open the drawer with bootstrap.Offcanvas.getOrCreateInstance(drawer).show().

Customization

  • data-oc-free-shipping="150" and data-oc-shipping="8" on .oc-shop: set the free-shipping threshold and the flat shipping fee.
  • data-oc-currency="USD" on .oc-shop: switch to EUR, GBP or any ISO currency code.
  • --oc-accent and --oc-accent-dark on .oc-shop in style.css: recolour the badge, shipping meter and checkout button.
  • --oc-drawer-width on .oc-shop: make the drawer wider or narrower on large screens.
  • MAX_QTY at the top of script.js: change the highest quantity per line.
  • Remove the show class from .oc-drawer to keep the cart closed until the cart button is clicked.
  • Replace .oc-thumb tiles with <img> elements for real product photos.

Use cases

  • Online stores: the cart slides in from the right when a shopper adds a product
  • Shop headers: a cart button with a badge shows the item count at all times
  • Product pages: quantity steppers and remove buttons update line totals and the subtotal
  • Promotions: a free-shipping progress meter encourages shoppers to add more to the cart

Accessibility

The drawer is labelled by its title through aria-labelledby, and the toggle uses aria-controls. The badge number is hidden from screen readers and repeated in .oc-badge-label, so the button reads "Cart, 4 items". Every stepper group has an aria-label naming the product, and each remove button says which item it removes. Changes are announced in the .oc-live status region; after a removal, focus moves to the next remove button or the close button. Disabled minus and plus buttons mark the quantity limits, and transitions are switched off with prefers-reduced-motion.

Usage notes

Requires Bootstrap 5 (added automatically) and Bootstrap Icons. The checkout button only simulates a delay: replace the timeout in its click handler with a fetch() call to your backend. Use a unique drawer id per instance.

Offcanvas Shopping Cart at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons
Layout
Responsive, works on mobile
Category
Drawers
License
Free for personal and commercial use

Questions about this template

Can I use the Offcanvas Shopping Cart code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Offcanvas Shopping Cart – free Bootstrap 5 drawer template
Offcanvas Shopping Cart · free Bootstrap 5 drawer template

More Drawers

Settings Drawer with Tabs – free Bootstrap 6 drawer template

Settings Drawer with Tabs

Dark Bootstrap 6 Drawer with tabbed settings panels (General, Alerts, Privacy), switches, a Range slider, select menus and a save bar that tracks unsaved changes.

Bottom Drawer Action Sheet – free Bootstrap 6 drawer template

Bottom Drawer Action Sheet

Bootstrap 6 bottom Drawer styled as a mobile action sheet with a share row, edit actions in a list group, pin toggle, delete action and confirmation toasts.

Filter Drawer for Product Lists – free Bootstrap 6 drawer template

Filter Drawer for Product Lists

Bootstrap 6 Drawer from the left with category checks, a Range price slider, feature toggles, rating, in-stock switch, live result count and apply/reset buttons.

Drawer Shopping Cart – free Bootstrap 6 drawer template

Drawer Shopping Cart

Bootstrap 6 Drawer shopping cart that slides in from the right with product rows, quantity steppers, a free-shipping progress bar, subtotal and checkout.

Notification Drawer Panel – free Bootstrap 5 drawer template

Notification Drawer Panel

Bootstrap 5 offcanvas notification drawer with notifications grouped by day, unread filter, mark all as read and dismiss buttons.

Slide-Over Panel – free Tailwind CSS drawer template

Slide-Over Panel

Tailwind CSS slide-over drawer from the right with header, scrollable form content, sticky footer actions, focus trap and Escape to close.