A privacy-first, zero-dependency cookie consent banner for Astro projects — built for speed, compliance, and total visual control.
Designed and maintained by Velohost.
Most cookie consent solutions are bloated, opaque, or tied to third-party services.
astro-consent is built differently:
- No trackers
- No remote calls
- No analytics SDKs
- No vendor lock-in
- No runtime dependencies
Just a fast, deterministic, developer-controlled consent layer that respects user privacy and legal boundaries.
- ✅ GDPR / UK GDPR friendly
- 🍪 Consent categories: Essential, Analytics, Marketing
- 🎛️ Preferences modal with toggle switches
- ⚡ Zero runtime dependencies
- 🎨 Fully themeable via CSS variables
- 🧠 Frontend-controlled script loading
- 🧩 Native Astro integration
- 🛠️ CLI installer & remover
- 🔁 Clean uninstall with no residue
- 🌍 Framework-agnostic frontend API
This package uses both an Astro integration and a CLI installer.
npm install astro-consentThis step is required so Astro can import the integration at build time.
npx astro-consentThis will automatically:
- Inject the Astro integration into
astro.config.* - Create
src/cookiebanner.cssfor theme control - Enable the consent banner across your site
No manual wiring required.
npx astro-consent removeThis cleanly removes:
- The integration entry
- Generated files
- All banner logic
No orphaned config. No hidden state.
import astroConsent from "astro-consent";
export default {
integrations: [
astroConsent({
siteName: "My Website",
policyUrl: "https://example.com/privacy-policy",
consent: {
days: 30,
storageKey: "astro-cookie-consent"
},
categories: {
analytics: false,
marketing: false
}
})
]
};-
policyUrl
A full, public URL to your Privacy or Cookie Policy page.
This is linked directly from the consent banner. -
consent.days
How long (in days) consent is stored before the user is asked again. -
consent.storageKey
ThelocalStoragekey used to persist consent.
You may change this freely if you need per-site or per-environment isolation. -
categories.analytics
Allows analytics scripts to load only after consent.
Typical use: Plausible, self-hosted analytics, Google Analytics. -
categories.marketing
Allows marketing and advertising scripts to load only after consent.
Typical use: ad pixels, remarketing tags, embedded social trackers.
Scripts outside the essential category must be conditionally loaded.
window.cookieConsent.get();
window.cookieConsent.set({ essential: true, analytics: true });
window.cookieConsent.reset();All visuals are controlled via:
src/cookiebanner.css
You must ensure this file is included globally.
Import the stylesheet once in your main layout or entry file:
import "../cookiebanner.css";This guarantees the banner styles are available on every page.
- This file is never overwritten
- All colours, spacing, radius, and animations are controlled via CSS variables
- Full visual control with zero JavaScript theming
- No cookies before consent
- No tracking without permission
- No external requests
- Stored locally with TTL
MIT © Velohost