Skip to content
Get started

GDPR Cookie Consent Banner for Astro

The free Cookiebot alternative

Cookie consent for Astro

A popular, tiny, dependency-free GDPR consent banner that actually gates your scripts, with Google Consent Mode v2 for GA4, Google Ads and GTM. No dark patterns, no pre-ticked boxes.

Get started
npm i astro-cookie-consent
Live previewDefault (dark)
Waiting for consent…

Trusted by startups, small businesses and technology companies

Add it to your site

Small enough to forget about

Plain .astro and .js source, compiled by your own build. Nothing to audit, nothing phoning home.

Latest release
—
Open-source license
MIT
Runtime dependencies
0
CSS variables to theme it
7

Drop the banner into your layout, then gate any third-party script behind consent.

That’s it — no config file, no CSS to write, no dependency to audit.

src/layouts/Layout.astro
---
import ConsentBanner from 'astro-cookie-consent/ConsentBanner.astro';
---
<html>
<body>
<slot />
<ConsentBanner privacyHref="/privacy" />
</body>
</html>
<script>
import { gateScript } from 'astro-cookie-consent';
gateScript({ src: 'https://example-widget.com/embed.js' });
</script>

The free Cookiebot alternative

Every feature you'd expect from a paid consent-management platform like Cookiebot, built into one free, dependency-free component. No monthly plan, no page-view limits, no third-party script.

Zero dependencies

Ships as plain .astro/.js source, compiled by your own project's Astro pipeline. No runtime dependencies.

Actually gates scripts

gateScript() blocks third-party scripts until the visitor accepts — not just an informational banner that lets trackers load anyway.

API reference

Per-category consent

Optional analytics/marketing-style category toggles, or a single accept/decline if you don't need that.

Learn more

Fully customizable

Every visual is 7 CSS custom properties and every string of copy is a prop. Follows the visitor's light or dark OS theme automatically.

Learn more

Google Consent Mode v2

<ConsentMode /> sends the visitor's choice to GA4, Google Ads and GTM as Consent Mode v2 signals, with a denied default before any Google tag runs.

Set it up

Works with AI coding agents

Ships a SKILL.md documenting its own API and guardrails, so an agent can safely customize it — change copy, gate a new script, add a theme — without guessing.

Learn more

Built for GDPR compliance

A cookie banner people can't actually use isn't compliant. These are the mechanics that regulators (CNIL, ICO, EDPB) actually check for — built in by default, not bolted on.

This library is a mechanism, not legal advice — your privacy policy, the categories you declare, and what you gate behind them are still on you. See exactly what this does and doesn’t cover →

No dark patterns

Accept and decline are given equal visual weight. No filled "Accept" button next to a washed-out "Decline" nudging visitors toward consent.

No pre-ticked boxes

Every category defaults to off. Genuine opt-in, not opt-out disguised as a choice.

Consent expires

Choices expire after a configurable period (365 days by default) and the banner reappears — no permanent silent consent from a choice made a year ago.

A record you can point to

Every choice is stored with a timestamp, retrievable via getConsentRecord() — something to show if you ever need to demonstrate consent was given (Art. 7(1) accountability).

Make it yours, down to the last pixel

Every visual is 7 CSS custom properties and every string of copy is a prop. No build step, no config file, no design system to fight.

Explore all 15 themes

Pricing

Free forever. Every feature, every site.

$0 no credit card, no account, ever

Get started
  • Unlimited sites
  • Every feature, no gated tiers
  • Per-category consent
  • Script gating with gateScript()
  • Google Consent Mode v2
  • All themes & full CSS customization
  • No account, no tracking, no telemetry
  • MIT licensed — open source, forever free.

Add consent to your site in two minutes