Back to components
ElementOverlayFree

Cookie Consent Banner React component

A cookie consent banner as a corner card or a bottom bar: accept all, reject all with equal weight, or open per-category switches (necessary locked on), and the choice is remembered, with a small button to change it later.

About the Cookie Consent Banner component

Cookie Consent Banner asks visitors for permission before optional cookies run. It slides in as a card in a corner or a bar along the bottom with Reject all and Accept all side by side, so saying no is as easy as saying yes. Customize opens a switch for each category, with strictly necessary cookies always on, and Save preferences stores the choice.

categories takes objects with id, label, description and optional required and defaultEnabled. title, message, policyHref and policyLabel set the text and the policy link. onConsentChange receives every category's on or off once the visitor decides, so you can load analytics or ad scripts then. The choice is stored in localStorage under storageKey and the banner stays hidden on later visits. showReopen leaves a small cookie button to change it, and delay sets the seconds before it appears.

When to use it

Use Cookie Consent Banner on any site that sets analytics, advertising or other non-essential cookies and needs the visitor's permission first. Reject is as easy as Accept, and people can pick categories one by one.

Load your scripts from onConsentChange rather than on page load, so nothing optional runs until the visitor says yes. Change storageKey when your cookie policy changes to ask everyone again.

Installation

Add the Cookie Consent Banner component to your project with the shadcn CLI. It lands in components/cookie-consent-banner.tsx as plain React + Tailwind CSS source you own and can edit.

Install
Copied!
npx shadcn@latest add @reactframe/cookie-consent-banner

Or copy the source by hand and install its dependencies:

Install
Copied!
npm install motion clsx tailwind-merge

Related components

Product Tour
Free
Lightbox
Free
Command Palette
Free
Bottom Sheet
Free
Confirm Dialog
Free
Drawer
Free