Made for India's DPDP Act, 2023 and DPDP Rules, 2025

The consent banner for India Your privacy choices

 

Consent per purpose, withdrawal in one click, and English plus the 22 languages of the Eighth Schedule. No dependencies, and your site's CSS cannot break it.

Try the playground
$ npm install consentbar
23languages
0dependencies
~19 KBgzipped, all languages
WCAG AAcontrast, keyboard ready
MITlicensed
23 languages

Pick a language. The banner switches live.

English and all 22 languages of the Eighth Schedule to the Constitution of India. Urdu, Kashmiri and Sindhi are shown right to left. Users can also switch languages from inside the banner.

The interface texts come built in. Your purpose names and descriptions are your own: this demo translates them into Hindi only, so other languages show them in English.

Playground

Change the options and watch every event

Each change rebuilds the bar with your options. The panel on the right shows the saved consent and every event, as your code would receive them.

Options

createConsentBar()
theme
position
floatingButton
--consentbar-accent
12px
Methods

Current consent

getConsent()
    Choice madeNo
    LanguageEnglish
    Notice version1
    Saved atNot yet
    Record IDNone
    Records in this browser0
    Each choice is saved as a record you can send to your server.

    Events

    • Events appear here. Click a button in the banner to start.
    Your options as code
    Script blocking

    Nothing runs until the user says yes

    Mark a script or iframe with data-consent and consentbar holds it back. It runs as soon as the user allows that purpose, without a page reload. The three boxes below are real blocked elements on this page.

    Analytics script

    Blocked

    An inline script that counts visits. It stays as plain text until Analytics is allowed.

    Waiting for consent
    Consent was withdrawn. A script that has already run keeps running until the page reloads.
    <script type="text/plain"
            data-consent="analytics">
      countVisits()
    </script>

    Marketing script

    Blocked

    A script that shows a personalised offer. It runs only after Marketing is allowed.

    Waiting for consent
    Consent was withdrawn. A script that has already run keeps running until the page reloads.
    <script type="text/plain"
            data-consent="marketing"
            src="/js/offers.js"></script>

    Embedded video

    Blocked

    An iframe from another site. Its src is set only after Embedded videos is allowed.

    Waiting for consent
    Consent was withdrawn. An embed that has already loaded stays until the page reloads.
    <iframe data-consent="video"
            data-src="https://video.example/42">
    </iframe>

    After withdrawing, to see the blocked state again.

    Features

    Built around the DPDP consent rules

    Everything a consent notice needs, in one small package that works with any framework.

    One switch per purpose

    Users agree to each purpose separately. All switches start off, and "Reject all" is as easy to click as "Accept all".

    Withdraw at any time

    A small "Privacy choices" button stays on the page. One click reopens the panel, so withdrawing is as easy as agreeing.

    A record of every choice

    Each choice becomes a record with a time, notice version and language. Send records to your server as proof of consent.

    Blocks trackers

    Scripts and iframes marked with data-consent wait until the user allows their purpose.

    Accessible

    Keyboard and screen reader support, focus handling in the panel, WCAG AA contrast in light and dark, and right-to-left scripts.

    Works everywhere

    Plain HTML, WordPress, React, Next.js and Vue. It draws in a Shadow DOM, so your site's CSS cannot break it.

    Install

    Add it in a few minutes

    Install from npm, or add one script tag if you have no build tools.

    // npm install consentbar
    import { createConsentBar } from 'consentbar'
    
    const bar = createConsentBar({
      purposes: [
        { id: 'essential', title: 'Essential', description: 'Keeps you signed in and protects your account.', required: true },
        { id: 'analytics', title: 'Analytics', description: 'Counts visits so we can improve the site.', dataItems: ['Pages visited', 'Device type'] },
      ],
      notice: {
        fiduciaryName: 'Example Pvt Ltd',
        privacyPolicyUrl: 'https://example.in/privacy',
        contactEmail: 'grievance@example.in',
      },
    })
    
    bar.hasConsent('analytics')   // false until the user agrees
    bar.on('change', ({ consent }) => console.log(consent.purposes))

    The full guide, including consent records, notice versions and the CSS variables, is in the README.