Slide-In Cart Drawer
An offcanvas cart drawer with checkout and a success alert.
Requires Bootstrap 5, SweetAlert2. Add the CDN tags below to your page (styles in
<head>, scripts before </body>). The downloaded file already includes them.<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><script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script><div><button class="btn btn-primary" id="cdOpen">🛒 Cart (2)</button>
<div class="offcanvas offcanvas-end" tabindex="-1" id="cdCanvas"><div class="offcanvas-header"><h6 class="fw-bold mb-0">Your cart</h6><button class="btn-close" data-bs-dismiss="offcanvas"></button></div>
<div class="offcanvas-body"><div class="d-flex justify-content-between mb-2 small"><span>Headphones</span><span>$129</span></div><div class="d-flex justify-content-between mb-3 small"><span>Cable</span><span>$12</span></div><hr><div class="d-flex justify-content-between fw-bold mb-3"><span>Total</span><span>$141</span></div><button class="btn btn-primary w-100" id="cdPay">Checkout</button></div></div></div>var oc=new bootstrap.Offcanvas('#cdCanvas');
document.getElementById('cdOpen').onclick=function(){oc.show()};
document.getElementById('cdPay').onclick=function(){oc.hide();Swal.fire({icon:'success',title:'Order placed!',timer:2000,showConfirmButton:false})};Free to use.This component uses Bootstrap 5, SweetAlert2 (linked above). Copy any file, or download a ready-to-open .html page with the CDN links already included.