Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Cookie Consent Settings Block for React

A cookie preferences page with four purpose cells on shared hairlines: necessary locked on in words, three switches, and under each the exact cookies it covers, kept for how long, set or blocked.

Framework
UI library

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Give visitors the page where they change their cookie choices, with this cookie settings block for React with Base UI. It is not a banner: it is the page a banner links to. Four cells share hairlines, one per purpose: necessary, preferences, analytics and marketing. Necessary is locked on and says why in words ("Always on. Without these the site can't keep you signed in or remember what you chose here"), with a lock and a disabled Switch that is still named. The other three are Switches, and each cell has a sentence that follows the switch, saying what happens when it is on and when it is off. Under it a list names every cookie the purpose covers, how long it is kept, and whether it is Set or Blocked at the moment, drawn as a filled or hollow dot with the word beside it and the name struck through when blocked. The band above the cells counts them ("6 of 10 set"), and the action foot counts the changes with a Shine Button and a Discard Button. It's built from Switch, Button, Shine Button and Guides, with a CSS entrance only. For a marketing site, a shop, a publication or any site that sets cookies.

FAQ

How do I list my own cookies?

Edit PURPOSES: each purpose has a title, the sentence for each state and its cookies, each with a name and how long it is kept. The cell, the per-cookie rows and the count in the band all read from that list, so adding a cookie to a purpose is one line. Keep the names and lifetimes true to what your site really sets: this page is the record people read.

Why can't the necessary cookies be turned off?

They are the ones the site cannot work without: the session that keeps you signed in, the token that blocks forged requests and the cookie that remembers these choices. The cell says so in words next to a lock, and its Switch is checked and disabled but still named for assistive technology ("Necessary cookies, always on"), so it is read, not skipped. Only list a cookie there if the site really breaks without it.

What stays local, and how do I make it real?

All of it, and nothing is written to cookies or storage: Save keeps the switches in this page's state, and a reload brings back the starting choices. To make it real, write the choices to your consent cookie on Save with a timestamp and a version of your policy, read them back before setting any cookie, and stop setting cookies of a purpose that is off (and delete the ones already set).

What do Set and Blocked mean?

A cookie is Set when its purpose is on (necessary always is) and Blocked when it is off, shown as a filled or a hollow dot with the word beside it and the name struck through, so state never rests on the dot alone. The count in the band follows the switches, so turning analytics on moves it from 5 to 8 of 10 set in this sample.

What do Save and Discard do?

They are always there and always answer. Save counts what changed and keeps it ("Saved 2 changes in this demo."), or says "No changes to save."; Discard puts the last saved choices back. The status line is a polite live region present from the start, and it says what each switch did ("Analytics cookies on.") until the change is saved or discarded.

How does it look on a phone, and by keyboard?

The four cells stack in one column and keep their switches at the end of the title row, and the Save and Discard foot stays pinned to the bottom of the screen while the page scrolls. Each switch is named for its purpose and described by its sentence, so a screen reader hears what the switch does before it is turned.

  • Pro

    Privacy Settings

    Privacy and consent

    A privacy panel with three presets that set five switches, a sentence that adds them up, and a row per setting that says in words what it means for you and what it shares.

  • Pro

    GDPR Consent Settings

    Privacy and consent

    A purposes register with a legal basis, retention and consent record per purpose, a rule that withdrawing must be as easy as giving, and three data requests counted down from 30 days.

  • Pro

    Cookie Consent Dialog

    Drawers and popovers

    A recipe blog's first-visit cookie card shown open over its page: two sentences, then Reject all and Accept all as two equal outline buttons side by side, with no primary. It isn't modal, so the page stays readable, and the choice is written on the page's foot.

  • Pro

    Cookie Consent Login

    Sign-up and consent

    A bakery subscription's cookie choices shown open over a drawn sign-in page: Essential locked on, Analytics and Marketing switches that start off, and three equal buttons, Reject all, Accept all and Save choices.

  • Pro

    A footer for a writing app whose legal row opens a cookie settings dialog with a switch per category and shows what was saved.

  • Pro

    A cookie prompt for an online shop: one split card with a stack of three equal-width choices, Accept all, Reject non-essential and Manage preferences.