Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Granular Consent Multi-Action Banner Block for React

A consent card for a publisher site: four categories as a 2 by 2 of switch cells on shared hairlines, Essential locked on, with a Shine Button Save choices and an outline Accept all.

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

A granular consent card for React with Base UI, for a visitor who wants to choose rather than accept everything. Nectarship's card sits between the page's solid rails with a + mark on each corner. A short header explains what Essential cookies do, then four categories sit in a 2 by 2 of cells on shared hairlines: Essential is locked on and says so, and Analytics, Marketing and Functional each have a switch and one line about what they are for. A footer counts the categories that are on and holds a Shine Button "Save choices" and an outline "Accept all". Either button folds the whole block away with a CSS height transition. It is a labelled region with real buttons, never a dialog, so nothing is trapped and the page behind stays usable. It's built from Guides, Switch and Button with your theme's tokens for every colour; checked switches are foreground, so the primary stays on Save. For publishers, shops and any site that needs per-category consent without a full preferences page.

FAQ

Is this a dialog? Does it trap focus?

No. It is a section named by its heading, in the flow of the page, with real switches and buttons, so people can read the page, tab past it or scroll on. Screen readers list it with the page's regions. To pin it to the bottom of the screen, put fixed inset-x-4 bottom-4 z-50 on the card's outer element (the one with max-w-2xl) and remove the py-8 md:py-12 padding on the wrapper above it. Add pb-[env(safe-area-inset-bottom)] if your layout needs it. It still never takes focus on its own.

How do I add, remove or rename categories?

Edit the CATEGORIES list at the top of the file: an id, a label, one description line and locked for a category that can't be turned off. The cells are generated from it and the count in the footer follows. Keep the list at four, or an even number, so the cells fill both columns of the grid and no hole shows the hairline colour; with an odd number, let the last cell span both columns with sm:col-span-2.

Why is Essential a switch that can't be moved?

Showing it as a locked switch tells people what is on without hiding it. The switch is disabled and starts on, and its description ends with "Always on", so a screen reader hears the name, the on state and the reason. Cookies that are strictly necessary don't need consent in most regions, so listing them is a courtesy rather than a choice.

What do Save choices and Accept all remember?

Nothing in this block: it forgets on purpose so the preview always shows it. Wire the two handlers to your consent store: write the allowed list to a first-party cookie, send it to your tag manager, and have the server skip rendering the card when the cookie exists. Reading a stored value after the first paint would show the card and then fold it away, moving the page, so decide on the server. Accept all sets every category to on before folding, and the footer count follows.

Where does keyboard focus go after the card closes?

The buttons can't keep focus once the card is folded and inert, so focus moves to a visually hidden line at the same spot, "Cookie choices saved.", which screen readers read. The next Tab carries on from there. With reduced motion the card closes at once.

Is Save weighted more than Accept all?

Save choices is the Shine Button and Accept all is an outline Button of the same size, so Save carries the colour. Some regulators read colour as weight; if yours does, make both buttons outline and drop the Shine Button, so accepting everything is never easier to spot than saving a partial choice.

How does it fit on a phone?

The cells stack in one column, each with its switch at the end and a description that wraps to two lines at most, and the footer stacks: the count, then Save and Accept all at full width. It stays under one screen at 320 pixels with nothing scrolling sideways, and in a right-to-left layout everything mirrors.

  • 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.

  • Pro

    An acknowledge-once callout for a newsletter platform: a card in card with an info icon, a heading, one sentence and a footer whose checkbox rewrites the outline button from Got it to Dismiss permanently.

  • Pro

    A region callout for a storefront: two cells split by a divider, a map pin and a live line at the start, and a US, EU and UK segment control at the end that rewrites the currency, tax and delivery line.

  • Pro

    A reading-preferences prompt for a reading app: three toggles with a live preview that changes size, weight and border, a polite count, and Save, Reset and Not now.

  • Pro

    A setting callout for an uptime monitor: a card in card with a bell icon, a heading and a sentence, and an Off or On label beside a switch that rewrites the sentence and lights a status dot.

  • Pro

    A trial prompt card for a video editor that sets what you have now beside what stays after the trial, in two columns, with upgrade, compare and remind-me-later actions.