cookieconsent
:cookie: Simple cross-browser cookie-consent plugin written in vanilla js
Alternatives
Tech stack
No tech stack added yet. Sign in to suggest some
Note: The official Playground page could not be fetched this time, so this entry is based on existing knowledge of the project. For specific details, please refer to the official documentation and the GitHub repository.
Introduction
cookieconsent (npm package name vanilla-cookieconsent) is an open-source cookie consent plugin maintained by developer Orest Bida. Written in vanilla JavaScript, it is small and has no third-party dependencies. It displays a cookie consent banner and a preferences panel on your website, helping the site comply with privacy regulations such as the GDPR. The official Playground is a visual configuration tool where developers can adjust the layout, styling, language and cookie categories, preview the result in real time, and then export the configuration code.
Key Features
- Consent modal and preferences modal: Provides a consent modal shown on the first visit (Consent Modal), plus a preferences panel (Preferences Modal) that lets users fine-tune their choices by category, with a variety of layouts and positions to choose from.
- Cookie category management: You can define categories such as necessary, analytics and advertising. The necessary category can be set to read-only and always enabled.
- Script blocking: After adding
type="text/plain"and adata-categoryattribute to a<script>tag, the script will not run until the user consents to the corresponding category. - Automatic cookie clearing: When a user withdraws consent for a category, the cookies belonging to that category can be deleted automatically.
- Multilingual support: Translations can be configured for multiple languages, with automatic switching based on the browser language or the page language.
- Callbacks and API: Offers callbacks such as
onFirstConsent,onConsentandonChange, as well as an API for querying and modifying the consent state, making it easy to integrate with analytics, advertising or Google Consent Mode tools. - Style customization: Colors, fonts, border radius and more can be changed with CSS variables, and dark mode is supported.
Target Users and Use Cases
It suits front-end developers, independent site owners and small and medium-sized businesses that need to add cookie consent to a website. The project is open source and can serve as an alternative to commercial consent management platforms (CMPs) such as OneTrust and Cookiebot. Common use cases include personal blogs, corporate websites, e-commerce sites and SaaS product landing pages.
Core Strengths
- Lightweight with no dependencies, so it has little impact on page performance
- Free and open source, giving you full control over the code. Consent data is stored locally in the user's browser and does not depend on any third-party service
- Framework-agnostic: it can be used in plain HTML and also integrated into projects built with React, Vue, Angular, Next.js and others
- Flexible configuration, with an online Playground to help generate it
Installation and Usage
Install via npm:
npm i vanilla-cookieconsent
import 'vanilla-cookieconsent/dist/cookieconsent.css';
import * as CookieConsent from 'vanilla-cookieconsent';
CookieConsent.run({
categories: { necessary: { readOnly: true }, analytics: {} },
language: { default: 'en', translations: { en: { /* 文案 */ } } }
});
You can also include the CSS and JS files via a CDN and then call CookieConsent.run() directly.
Technical Requirements
- Supports modern browsers
- Runs only on the front end and requires no server-side components
Worth Noting
This plugin only provides the technical tooling. Whether your website is compliant also depends on whether the cookie categories, wording and script blocking are configured properly. If necessary, we recommend consulting a legal professional.
Discover more
0 A.D.
Cross-platform real-time strategy game of ancient warfare.
0 A.D.
Cross-platform real-time strategy game of ancient warfare.
1time
Zero-knowledge one-time secret sharing. End-to-end encrypted, self-hosted, open source.
4ga Boards
Straightforward realtime kanban boards management for intuitive task tracking. Featuring an elegant dark mode, collapsible todo lists, and multitasking tools to supercharge your team's productivity.
ACP Admin
CSA administration. Manage members, subscriptions, deliveries, drop-off locations, member participation, invoices and emails (documentation in French).
AFFiNE
There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.