webdevpuneet.com

Bootstrap Cookie Consent Offcanvas Panel — Free Snippet

Bootstrap Cookie Consent Offcanvas Panel · Modals · Plain HTML, CSS & JS · Live preview

CategoryModals

Copy & paste

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 &amp; 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>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month, 7 days free), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Real Bootstrap 5.3 Offcanvas component, anchored to the bottom edge like a genuine banner
No backdrop — data-bs-backdrop="false" keeps the page fully interactive behind it
Opens automatically on load via panel.show(), not waiting for a user click
Expandable "Customize" section with real Bootstrap form-switch toggles per cookie category
Essential cookies toggle is permanently on and disabled, matching real compliance requirements
Two-tier consent flow — one-click accept/reject, or granular per-category control

About this UI Snippet

Bootstrap Cookie Consent Offcanvas Panel — HTML, CSS & JavaScript

Screenshot of the Bootstrap Cookie Consent Offcanvas Panel snippet rendered live

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.

Step by step

How to Use

  1. 1
    Load the snippetClick the snippet in the sidebar Library tab. The panel opens automatically from the bottom, with no dark backdrop dimming the page.
  2. 2
    Click "Accept all" or "Reject all"The panel closes; check the browser console to see the logged choice.
  3. 3
    Click "Customize" insteadA preferences section expands below with per-category toggle switches.
  4. 4
    Adjust toggles and saveToggle Analytics/Marketing and click "Save preferences" — the panel closes with your custom choice.
  5. 5
    Trigger it againClick "Reset & show again" to see the panel appear fresh, preferences collapsed.

Real-world uses

Common Use Cases

GDPR/cookie-law compliant consent banners
A functioning starting point for the accept/reject/customize consent pattern most privacy regulations expect.
Learning Offcanvas without a backdrop
A clear example of using Bootstrap's Offcanvas as a non-blocking banner rather than its more common full-overlay use.
Any site needing granular consent categories
The expandable preferences pattern generalizes to notification preferences or any other opt-in/opt-out category set.
Sites requiring the page to stay usable during consent
A backdrop-free banner ensures visitors relying on assistive tech or partial page reading aren't blocked while deciding.

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.