Cybersecurity

Cookie Consent Banners: What the Law Requires

November 27, 2026 · 12 min read

Cookie Consent Banners: What the Law Requires

Cookie consent is the permission a website or app must obtain before storing or reading non-essential information on a visitor's device, such as analytics or advertising cookies, tracking pixels and fingerprinting scripts. In Europe and the UK, the rule comes from e-privacy law, and the GDPR defines what valid consent means: freely given, specific, informed and unambiguous. That is why nearly every European website shows a banner, and why so many of those banners still break the law.

Regulators are not letting up. In September 2025, France's CNIL fined Google €325 million and Shein €150 million, largely for cookie failures: Google for setting advertising cookies during account creation without valid consent, and Shein for placing cookies without consent and continuing to use them after visitors refused. Meanwhile, the UK relaxed some rules in 2026 and the EU is debating reforms. This guide explains what the law requires today, the banner designs that get fined, how to build compliant consent logic with tested code, and what is changing.

When You Need Consent, and When You Don't

Type of cookie or technologyEUUK (from February 2026)United States (typical)
Strictly necessary: login sessions, shopping carts, security, load balancing, remembering the consent choiceNo consent neededNo consent neededNo consent needed
Preferences such as language or theme the user choseOften treated as necessary when the user requested itExempt as "appearance and functionality", with information and a way to objectNo consent needed
First-party analytics to improve the serviceConsent usually needed; narrow exemptions exist in some countries, such as FranceExempt for statistical purposes, with clear information and a simple way to objectDisclose; opt-out may apply
Third-party analytics that combine data across sitesConsent neededConsent neededOften counts as "sharing"; opt-out required in many states
Advertising, retargeting, social media pixelsConsent neededConsent neededOpt-out of "sale or sharing" and targeted advertising

The rules cover any technology that stores or accesses information on a device, not just cookies: local storage, pixels, SDKs in mobile apps and device fingerprinting are all included.

What a Lawful Cookie Banner Looks Like

  • Nothing optional runs before a choice. Analytics and advertising scripts must stay blocked until the visitor agrees.
  • Rejecting is as easy as accepting. "Reject all" belongs on the first layer, with the same size and prominence as "Accept all".
  • No pre-ticked boxes. The EU's highest court confirmed in its 2019 Planet49 ruling that pre-checked boxes do not give valid consent.
  • Granular and informed. Visitors can choose by purpose, and can see which companies receive their data and for how long.
  • Withdrawing is as easy as consenting, through a permanent "Cookie settings" link.
  • Choices are respected and remembered, including refusals, without nagging visitors on every page.
  • Consent is recorded, so you can prove what each visitor agreed to and when.

Dark Patterns That Get Fined

Most enforcement targets the same handful of tricks:

  • Hiding "Reject" behind "Manage options" while "Accept" is one bright click away. The CNIL fined Google and Facebook a combined €210 million in 2022 for exactly this.
  • Cookies before consent: tags that fire on page load, before the banner is even answered.
  • Ignoring refusals. In Shein's case, cookies kept being set even after visitors refused or withdrew consent.
  • Bundling consent with sign-up, so that creating an account means accepting advertising cookies, which was part of Google's 2025 fine.
  • "Legitimate interest" toggles switched on for tracking that legally requires consent.
  • Misleading colours and wording, such as a grey, tiny reject link or "Continue" that secretly means "Accept".

Build It: Consent Logic as Testable Code

Many sites use a consent management platform, but the rules behind any banner are simple enough to express, and test, in code. Here are the core decisions as pure functions: when to show the banner, what "Accept all" and "Reject all" mean, which script categories may run, and the matching Google Consent Mode signals.

// consent-core.mjs: the decisions behind a lawful cookie banner, as testable functions
export const CATEGORIES = ["necessary", "analytics", "marketing"];
const SIX_MONTHS = 182 * 24 * 60 * 60 * 1000;

// 1. Should we show the banner, or apply a stored or browser-signalled choice?
export function initialState({ stored, gpc, now }) {
  if (stored && now - stored.savedAt < SIX_MONTHS) return { showBanner: false, choice: stored.choice };
  if (gpc) return { showBanner: false, choice: { analytics: false, marketing: false }, note: "Global Privacy Control honoured" };
  return { showBanner: true, choice: { analytics: false, marketing: false } }; // nothing optional runs before a choice
}

// 2. Accept all and Reject all must be equally easy: both are one click
export const acceptAll = () => ({ analytics: true, marketing: true });
export const rejectAll = () => ({ analytics: false, marketing: false });

// 3. Which scripts may run?
export function allowedCategories(choice) {
  return CATEGORIES.filter((c) => c === "necessary" || choice[c] === true);
}

// 4. Google Consent Mode v2 signals that match the choice
export function consentModeUpdate(choice) {
  const v = (on) => (on ? "granted" : "denied");
  return {
    analytics_storage: v(choice.analytics),
    ad_storage: v(choice.marketing),
    ad_user_data: v(choice.marketing),
    ad_personalization: v(choice.marketing),
  };
}

// ---- tests ----
const now = Date.parse("2026-11-27T10:00:00Z");
console.log("first visit:", JSON.stringify(initialState({ stored: null, gpc: false, now })));
console.log("GPC browser:", JSON.stringify(initialState({ stored: null, gpc: true, now })));
const stale = { choice: acceptAll(), savedAt: Date.parse("2026-03-01T00:00:00Z") };
console.log("choice older than 6 months -> ask again:", initialState({ stored: stale, gpc: false, now }).showBanner);
console.log("after Reject all:", allowedCategories(rejectAll()).join(", "));
console.log("after Accept all:", allowedCategories(acceptAll()).join(", "));
console.log("consent mode:", JSON.stringify(consentModeUpdate({ analytics: true, marketing: false })));

Running the tests with Node.js prints:

first visit: {"showBanner":true,"choice":{"analytics":false,"marketing":false}}
GPC browser: {"showBanner":false,"choice":{"analytics":false,"marketing":false},"note":"Global Privacy Control honoured"}
choice older than 6 months -> ask again: true
after Reject all: necessary
after Accept all: necessary, analytics, marketing
consent mode: {"analytics_storage":"granted","ad_storage":"denied","ad_user_data":"denied","ad_personalization":"denied"}

The tests encode the legal requirements directly: nothing optional runs on a first visit, a refusal keeps only necessary scripts, a browser's Global Privacy Control signal is honoured as a refusal, and an old choice is renewed after six months. Here is how the same functions connect to the page. Optional scripts are added with type="text/plain" so the browser does not run them until consent switches them on:

// banner.mjs (browser): wire the decisions to the page
import { initialState, acceptAll, rejectAll, allowedCategories, consentModeUpdate } from "./consent-core.mjs";

const KEY = "consent-v1";
const stored = JSON.parse(localStorage.getItem(KEY) ?? "null");
const state = initialState({ stored, gpc: navigator.globalPrivacyControl === true, now: Date.now() });

function apply(choice, save) {
  if (save) localStorage.setItem(KEY, JSON.stringify({ choice, savedAt: Date.now() }));
  window.gtag?.("consent", "update", consentModeUpdate(choice));
  // Activate blocked scripts such as <script type="text/plain" data-category="analytics" src="...">
  for (const category of allowedCategories(choice)) {
    for (const blocked of document.querySelectorAll(`script[type="text/plain"][data-category="${category}"]`)) {
      const live = document.createElement("script");
      live.src = blocked.src;
      blocked.replaceWith(live);
    }
  }
  document.querySelector("#cookie-banner")?.setAttribute("hidden", "");
}

if (state.showBanner) {
  document.querySelector("#cookie-banner")?.removeAttribute("hidden");
  document.querySelector("#accept-all").addEventListener("click", () => apply(acceptAll(), true));
  document.querySelector("#reject-all").addEventListener("click", () => apply(rejectAll(), true));
} else {
  apply(state.choice, false);
}

// A permanent "Cookie settings" link lets people change their mind as easily as they agreed
document.querySelector("#cookie-settings")?.addEventListener("click", () => {
  localStorage.removeItem(KEY);
  location.reload();
});

If you use Google tags, load default "denied" signals before any tag runs, then send an update when the visitor chooses. Google's Consent Mode documentation describes the four signals; for advertising in the EEA, Google requires them to be passed correctly.

// consent-default.js: load this BEFORE any Google tag, so nothing is stored until the visitor chooses
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }

gtag("consent", "default", {
  ad_storage: "denied",
  ad_user_data: "denied",
  ad_personalization: "denied",
  analytics_storage: "denied",
  wait_for_update: 500, // milliseconds to wait for the banner to report a saved choice
});

Keep the banner light: a heavy consent script that blocks rendering or shifts the layout hurts Core Web Vitals, as our guide on how to make a website load faster explains.

Consent Management Platforms vs Doing It Yourself

A consent management platform (CMP) scans your site for cookies, blocks scripts automatically, provides translated banners, stores consent records and integrates with advertising frameworks such as the IAB's Transparency and Consent Framework. Publishers that show Google ads in the EEA, UK or Switzerland must use a Google-certified CMP. Building your own, as above, suits simple sites with a few analytics and marketing tags and gives full control over performance and design. Either way, test the result: open your site in a private window, check the browser's storage before clicking anything, then confirm that "Reject all" really leaves only necessary cookies.

Consent in Mobile Apps and Single-Page Apps

The same rules apply inside apps. Analytics, advertising and attribution SDKs read and store information on the device, so in the EU and UK they need consent before they start, exactly like website tags. On iOS there is an extra layer: Apple's App Tracking Transparency framework requires apps to ask permission before tracking people across other companies' apps and websites, and that system prompt does not replace the consent your privacy law requires. Ask for both in a sensible order, and only initialise tracking SDKs once the answers allow it. Our guide to mobile app security best practices covers the wider checklist.

In React and other single-page apps, keep consent in one place, such as a context provider that wraps the consent functions above, and let components check allowedCategories() before loading an embed, a chat widget or a video player that sets cookies. Because single-page apps change pages without a full reload, make sure analytics page-view events also respect the current consent state, and that withdrawing consent stops future tracking straight away rather than on the next visit.

The UK After the Data (Use and Access) Act

The UK has diverged from the EU. Changes made by the Data (Use and Access) Act 2025 took effect on 5 February 2026, adding exemptions so that some cookies no longer need consent. As CMS explains, the statistics exemption covers analytics used solely to improve your own service, but not third-party analytics providers that combine data for their own purposes. Other exemptions cover appearance and functionality choices, security and emergency assistance. Visitors must still get clear information and a simple way to object. The ICO published its final guidance on storage and access technologies on 29 April 2026, and the Act raised maximum fines for e-privacy breaches to UK GDPR levels, so the stakes for getting advertising consent wrong have risen.

What the EU Digital Omnibus Could Change

In November 2025 the European Commission proposed a Digital Omnibus package that would move cookie rules into the GDPR, require websites to respect automated privacy signals set once in a browser, and stop sites asking again for six months after a refusal. The proposal is still being negotiated: in June 2026 the Council's position dropped the browser-signal article entirely, and the European Parliament's lead committee had still not voted on its position by mid-September 2026. As Freshfields notes, nothing changes until a final text is adopted, so today's e-privacy and GDPR rules still apply in full.

United States: Opt-Out and Global Privacy Control

Most US state privacy laws use an opt-out model rather than prior consent: you may use analytics and advertising cookies, but you must disclose them and let people opt out of the "sale" or "sharing" of personal information and of targeted advertising. California and several other states require businesses to treat a browser's Global Privacy Control signal as a valid opt-out, which is why the code above checks navigator.globalPrivacyControl. If you serve both Europe and the US, the simplest approach is one consent-first banner that also honours GPC everywhere. Describe all of this in your privacy policy, and see our guide to data privacy laws for developers for the wider legal picture.

Cookie Consent Checklist

  1. Audit every cookie, pixel and SDK, and classify each by purpose.
  2. Block non-essential scripts until consent, including tags added later by marketing tools.
  3. Put "Accept all" and "Reject all" on the first layer with equal prominence.
  4. Explain purposes, vendors and durations in plain language.
  5. Add a permanent "Cookie settings" link to withdraw or change consent.
  6. Record consent with a timestamp and version.
  7. Honour Global Privacy Control, and pass Consent Mode signals if you use Google tags.
  8. Re-test after every new tag, plugin or redesign, because a tag that quietly sends personal data to a third party can become a reportable incident under your data breach response plan.

Frequently Asked Questions

Is cookie consent required by law?

In the EU and UK, yes, for non-essential cookies and similar technologies. In most US states, you must instead disclose tracking and offer an opt-out from sale, sharing and targeted advertising.

Do I need consent for Google Analytics?

In the EU, generally yes. In the UK, first-party analytics used only to improve your own service can be exempt since February 2026, but you must still inform visitors and let them object, and third-party uses beyond that need consent.

Does the "Reject all" button have to be as visible as "Accept all"?

European regulators expect refusing to be as easy as accepting, which in practice means both options on the first layer with similar prominence.

Can I use a cookie wall?

Blocking access unless visitors accept tracking is generally not allowed in the EU and UK. Some regulators accept "consent or pay" models in limited circumstances, but they face strict scrutiny.

How long does cookie consent last?

No single legal limit applies. Many sites renew consent every six to thirteen months, and regulators expect you to remember refusals rather than asking again on every visit.

What is Google Consent Mode?

It is a way of telling Google tags whether a visitor consented to analytics and advertising storage. With "denied" signals, Google tags avoid setting cookies, and Google requires correct signals for advertising features in the EEA.

Get Consent Right Without Hurting Performance

We build fast, compliant cookie banners and consent logic for websites and apps, audit trackers and connect consent to analytics and advertising tools properly. Contact our team for a cookie compliance review.

Want this built for you?

Our team offers Website Deploy On Vercel — get a free quote.

View Services