Installation & Quick Start
import { Steps } from ‘@astrojs/starlight/components’;
Install
Section titled “Install”npm install astro-cookie-consentThe only peer requirement is Astro >=4.0.0.
Quick start
Section titled “Quick start”-
Render
<ConsentBanner />once, globally, from your layout:src/layouts/Layout.astro ---import ConsentBanner from 'astro-cookie-consent/ConsentBanner.astro';---<html><body><slot /><ConsentBanner privacyHref="/privacy" /></body></html> -
Gate any third-party script behind that consent:
<script>import { gateScript } from 'astro-cookie-consent';gateScript({ src: 'https://example-widget.com/embed.js' });</script>gateScriptnever injects the script until the visitor accepts, and never injects it twice. -
That’s it. No CSS to write, no config file — the banner is a self-contained bottom-left card that already follows the visitor’s light/dark preference.
Next steps
Section titled “Next steps”- Need separate analytics/marketing toggles instead of one accept/decline? See Per-category consent.
- Want to match your brand colors? See Theming & dark mode.
- Building with an AI coding agent? The package ships a
SKILL.md— see Using with AI coding agents.