Skip to content

Bottom cookie banner in React

A full-width banner pinned to the bottom of the screen, with refuse, customize and accept on the same level.

Here is an excerpt of this component's code in React. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in React

BottomCookieBanner.tsx
import { useId, useRef, useState, useSyncExternalStore } from "react";
import { flushSync } from "react-dom";

export type Consent = Record<string, boolean>;

const STORAGE_KEY = "forge-consent";
// The CNIL recommends asking again after six months.
const MAX_AGE = 1000 * 60 * 60 * 24 * 182;
const categories = [
  {
    id: "analytics",
    label: "Mesure d'audience",

Free component: copy it freely, including for commercial projects.

Cookie banners components in React
  • A rounded dark bar floating at the bottom of the screen, text on the left and buttons on the right on large screens.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An understated banner with square corners and a thick rule, suited to local authorities, firms and public institutions.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A floating card in the bottom-left corner, discreet yet always visible.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A banner at the top of the page, in the document flow, that never hides content.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component