Cookie Banner
Floating bottom cookie consent bar with accept and decline actions.
We use cookies to improve your experience and analyze traffic. Read our cookie policy for details.
<div class="relative w-full h-56 rounded-xl bg-slate-100 overflow-hidden">
<div class="absolute bottom-3 left-3 right-3 rounded-xl bg-white shadow-lg border border-slate-200 p-4">
<p class="text-sm text-slate-600 mb-3">We use cookies to improve your experience and analyze traffic. Read our cookie policy for details.</p>
<div class="flex gap-2 justify-end">
<button class="px-4 py-2 text-sm rounded-lg border border-slate-300 text-slate-700 hover:bg-slate-50">Decline</button>
<button class="px-4 py-2 text-sm rounded-lg bg-slate-900 text-white hover:bg-slate-800">Accept</button>
</div>
</div>
</div>Free to use in personal and commercial projects. No attribution required.
Variants
Same component, different looks. Preview each one live and copy the code you like.
Top bar
The slim top bar suits content sites where a bottom banner would cover reading.
We use cookies to improve your experience. See our cookie policy.
Centered dialog
The centered dialog works when consent must be collected before the user continues.
We value your privacy
We use cookies to improve your experience and analyze traffic.
Dark
The dark banner blends into footers and dark-themed sites.
We use cookies to improve your experience and analyze traffic. Read our cookie policy for details.
About this cookie banner
A cookie consent banner is the small floating bar that asks visitors to accept tracking cookies, required in many regions before analytics scripts may run. The floating card style feels lighter and more modern than the old full-width strip.
The bar is absolutely positioned at the bottom of its container with left and right offsets, so it floats as a rounded card with a soft shadow. Two buttons, a quiet Decline and a solid Accept, present a genuine choice, and the copy stays to two lines so it never dominates the screen.
Show it once per visitor and remember the choice in localStorage. Keep the copy short and link to your cookie policy. Never pre-tick consent or hide the decline option, since regulators treat that as no consent at all.
Privacy law in many regions forbids running analytics before the visitor consents, which turned the cookie banner from a courtesy into a legal gate. The floating card style answers with lightness: a small rounded panel instead of the old full-width strip, asking a genuine question without hijacking the page. Done well, it earns trust; done badly, it trains users to click Accept blindly.
The bar is absolutely positioned at the bottom of its container with left and right offsets, floating as a rounded card with a soft shadow. Two buttons, a quiet Decline and a solid Accept, present a real choice, and the copy holds to two lines so the banner never dominates the viewport. It is a card, not a wall.
Wait 1 to 2 seconds before showing the banner so it doesn't ambush the visitor mid-hero-read; instant banners train users to dismiss without reading. Remember the choice in localStorage and never show the banner again on return visits; re-asking is how you teach contempt. On mobile, dock it full-width at the bottom with safe-area padding; a floating card there collides with thumbs. Keep the accept button visually primary but the reject option equally clickable; dark patterns here are increasingly illegal, not just rude.
The vague banner is the compliance failure: We use cookies to improve your experience with an Accept button tells the user nothing and satisfies no regulator. Name the actual categories, analytics and marketing, say what each does in a line, and link the full policy. Consent collected from confusion is not consent, and several regulators have said so explicitly.
Where to use it
- ✓ GDPR and privacy compliance banners
- ✓ Analytics opt-in prompts
- ✓ Marketing cookie consent
- ✓ Preference center entry points
Customization tips
On small phones, reduce the side offsets so the card uses the full width comfortably. For a subtler look, dock it bottom-right as a compact card with max-w-sm and ml-auto, and recolor the buttons to your brand palette.
Design notes
When to use
A cookie banner is required in many regions before analytics or tracking scripts may run, so use it when your site sets non-essential cookies and your visitors include the EU or UK. The floating card style feels lighter than a full-width bar and is easier to dismiss, which respects the visitor. Place it where it does not cover your main call to action.
What to avoid
Do not use dark patterns: an accept button that is big and bright next to a decline link hidden in tiny gray text will erode trust and can violate regulations. Do not block the whole page until someone clicks, and do not show the banner again after a choice was made, because nagging undoes the consent you collected.
Accessibility
Both accept and decline must be keyboard reachable real buttons with equal visual weight, and the banner should not auto-dismiss while someone is reading it. Use plain language that says what the cookies do, not legal jargon.
Frequently asked questions
Where should the banner appear on the page?
Fixed or absolute at the bottom, above all content with a high z-index. Bottom placement interrupts reading the least while staying impossible to miss.
Do I really need both Accept and Decline buttons?
Yes. Valid consent must be a genuine choice, so rejecting has to be as easy as accepting. A single OK button does not count as consent under EU rules.
How do I remember the visitor's choice?
Store the decision in localStorage when a button is clicked, and check for it before showing the banner. Only load tracking scripts after an accept has been recorded.
Can I pre-tick the analytics checkbox in my cookie banner?
No. Under GDPR, consent must be a clear affirmative action, and pre-ticked boxes do not count as consent. Leave every non-essential category unchecked by default and let the visitor opt in. Regulators have fined companies specifically for pre-ticked consent boxes.
Should the Accept and Reject buttons look the same?
Yes, give them equal size, color weight, and placement. Making Accept a big bright button while hiding Reject in small gray text is a dark pattern that violates the freely given requirement. Side-by-side buttons of equal prominence are the safest design.
What should the cookie banner text actually say?
Say what you collect and why in one plain sentence, list the categories like necessary, analytics, and marketing, and link to the full cookie policy. Avoid vague lines like we value your privacy with no specifics. Name the categories in the banner itself so users decide without opening another page.