Source Code
<div class="container py-5 text-center">
<p class="text-muted small">This preview auto-opens the cookie panel on load. Click "Reset" to trigger it again.</p>
<button class="btn btn-sm btn-outline-dark" id="bscookieReset">Reset & show again</button>
</div>
<div class="offcanvas offcanvas-bottom bscookie-panel" tabindex="-1" id="bscookiePanel" data-bs-backdrop="false">
<div class="offcanvas-body d-flex flex-wrap align-items-center gap-3 justify-content-between">
<p class="mb-0 small">We use cookies to improve your experience and analyze traffic. See our <a href="javascript:void(0)">Cookie Policy</a>.</p>
<div class="d-flex gap-2 flex-shrink-0">
<button class="btn btn-sm btn-outline-secondary" id="bscookieCustom">Customize</button>
<button class="btn btn-sm btn-outline-dark" id="bscookieReject">Reject all</button>
<button class="btn btn-sm btn-dark" id="bscookieAccept">Accept all</button>
</div>
</div>
<div class="bscookie-prefs d-none" id="bscookiePrefs">
<div class="offcanvas-body pt-0">
<div class="form-check form-switch"><input class="form-check-input" type="checkbox" checked disabled><label class="form-check-label small">Essential (always on)</label></div>
<div class="form-check form-switch"><input class="form-check-input" type="checkbox" id="bscookieAnalytics"><label class="form-check-label small">Analytics</label></div>
<div class="form-check form-switch"><input class="form-check-input" type="checkbox" id="bscookieMarketing"><label class="form-check-label small">Marketing</label></div>
<button class="btn btn-sm btn-dark mt-2" id="bscookieSave">Save preferences</button>
</div>
</div>
</div>.bscookie-panel { max-height: none; }
.bscookie-prefs { border-top: 1px solid #eceef1; }const panelEl = document.getElementById('bscookiePanel');
const panel = bootstrap.Offcanvas.getOrCreateInstance(panelEl, { backdrop: false });
const prefs = document.getElementById('bscookiePrefs');
function close(choice) {
console.log('cookie choice:', choice);
panel.hide();
}
document.getElementById('bscookieAccept').addEventListener('click', () => close('accept-all'));
document.getElementById('bscookieReject').addEventListener('click', () => close('reject-all'));
document.getElementById('bscookieCustom').addEventListener('click', () => prefs.classList.toggle('d-none'));
document.getElementById('bscookieSave').addEventListener('click', () => close('custom'));
document.getElementById('bscookieReset').addEventListener('click', () => { prefs.classList.add('d-none'); panel.show(); });
// A cookie banner should appear without requiring a click first — Bootstrap's
// offcanvas only opens on request, so this shows it once automatically.
panel.show();Bootstrap Cookie Consent Offcanvas Panel — Free Snippet
Bootstrap Cookie Consent Offcanvas Panel · Modals · Plain HTML, CSS & JS · Live preview
What's included
Features
About this UI Snippet
Bootstrap Cookie Consent Offcanvas Panel — HTML, CSS & JavaScript

A cookie banner shouldn't block the page behind a dark backdrop the way a real modal does — visitors need to keep reading while deciding. This snippet uses real Bootstrap 5.3's Offcanvas component with data-bs-backdrop="false" (also set in its JavaScript options), anchored to offcanvas-bottom so it reads as a banner rather than a full dialog, opened automatically once via panel.show() on load rather than waiting for a click.
Clicking "Customize" reveals a second section with per-category toggle switches (Essential, permanently on and disabled; Analytics; Marketing) using Bootstrap's real form-switch component — a common two-tier consent pattern: accept or reject everything in one click, or drill into specifics only if you choose to.
Build with AI
Build, Understand, Optimize, and Extend It With AI
Hand this snippet's HTML, CSS, and JS to an AI coding assistant like Claude and ask it to persist the consent choice to localStorage and only show the panel if no choice is recorded yet, or to actually gate a real analytics script tag behind the Analytics toggle's saved state. It's also a good exercise to ask the assistant to add a "Manage cookie preferences" link in the site footer that reopens the panel at any time.
Prompt to recreate it
Copy this into your AI assistant of choice to build the effect from scratch, or as a jumping-off point for your own variant:
Build a Bootstrap 5.3 cookie consent banner using the Offcanvas component, using the real Bootstrap CDN framework (bootstrap.min.css and bootstrap.bundle.min.js), not custom CSS made to resemble Bootstrap.
Requirements:
- A real Bootstrap offcanvas anchored to the bottom of the screen (offcanvas-bottom), initialized with backdrop disabled (both the data-bs-backdrop="false" attribute and matching JavaScript option) so the page behind it stays fully visible and interactive.
- The panel must open automatically on page load via JavaScript (not require a user click to first appear), with Accept all, Reject all, and Customize buttons.
- Clicking Customize must reveal an additional section with per-category toggle switches (using Bootstrap's real form-switch component) for at least Essential (permanently on, disabled), Analytics, and Marketing, plus a Save preferences button.
- Any of Accept all, Reject all, or Save preferences must close the offcanvas panel using Bootstrap's real Offcanvas JavaScript API.Want to tighten it up first? Run this prompt through the AI Prompt Studio to score it across 8 quality dimensions, catch anti-patterns, and tune the wording for Claude, ChatGPT, or Gemini before you paste it in.
Step by step
How to Use
- 1Load the snippetClick the snippet in the sidebar Library tab. The panel opens automatically from the bottom, with no dark backdrop dimming the page.
- 2Click "Accept all" or "Reject all"The panel closes; check the browser console to see the logged choice.
- 3Click "Customize" insteadA preferences section expands below with per-category toggle switches.
- 4Adjust toggles and saveToggle Analytics/Marketing and click "Save preferences" — the panel closes with your custom choice.
- 5Trigger it againClick "Reset & show again" to see the panel appear fresh, preferences collapsed.
Real-world uses
Common Use Cases
Got questions?
Frequently Asked Questions
data-bs-backdrop="false" (set both as an attribute and in the JavaScript initialization options) tells Bootstrap's Offcanvas component not to render its usual dark backdrop, so the rest of the page stays fully visible and interactive.
This demo logs the choice to the console. Replace that with a real implementation — setting a cookie or localStorage flag, and only calling panel.show() on load if no prior choice is recorded.
Clicking it toggles a d-none class on a second offcanvas-body section containing three Bootstrap form-switch toggles, one of which (Essential) is permanently checked and disabled since essential cookies typically can't be opted out of under most cookie laws.
No — this is a UI pattern only. Real cookie-consent enforcement requires actually gating your analytics/marketing scripts behind the recorded consent choice, which is outside the scope of this front-end snippet.
Yes — change offcanvas-bottom to offcanvas-top on the panel element; the JavaScript logic is unaffected by which edge it's anchored to.