Cookie consent banner as a Web Component. Works in any HTML page or framework.
A framework-agnostic Web Component for adding TinyConsent cookie consent banners. Use <tiny-consent> anywhere - vanilla HTML, Vue, Angular, Svelte, or any other framework.
- 🌐 Framework agnostic - Works everywhere: HTML, Vue, Angular, Svelte, etc.
- 🚀 One element - Just
<tiny-consent script-id="..." /> - 📦 Tiny - Under 1KB, loads the actual banner async
- ✅ Cookie consent compliance - Blocks scripts until user consents
- 🔧 Google Consent Mode v2 - Automatic GA4 integration
- 🎨 Customizable - Configure via dashboard, no code changes
- 🔌 Auto-registers - Just import and use
Get your script ID: tinyconsent.com/cookie-banner-generator
npm install tinyconsent-webcomponentyarn add tinyconsent-webcomponentpnpm add tinyconsent-webcomponentOr use via CDN:
<script type="module">
import 'https://esm.sh/tinyconsent-webcomponent';
</script><!DOCTYPE html>
<html>
<head>
<script type="module">
import 'tinyconsent-webcomponent';
</script>
</head>
<body>
<tiny-consent script-id="your-script-id"></tiny-consent>
<!-- Your content -->
</body>
</html><!DOCTYPE html>
<html>
<head>
<script type="module">
import 'https://esm.sh/tinyconsent-webcomponent';
</script>
</head>
<body>
<tiny-consent script-id="your-script-id"></tiny-consent>
</body>
</html>That's it! Your cookie consent banner will appear automatically.
The <tiny-consent> element injects:
<script src="https://scripts.tinyconsent.com/api/scripts/your-script-id" async></script>No internal logic, no bloat - just loads your cookie banner script on connectedCallback.
| Attribute | Type | Default | Description |
|---|---|---|---|
script-id |
string |
Required | Your TinyConsent script ID |
async |
string |
"true" |
Load script asynchronously |
defer |
string |
"false" |
Defer script execution |
| Event | Detail | Description |
|---|---|---|
load |
- | Fired when script loads |
error |
Error |
Fired if script fails to load |
const consent = document.querySelector('tiny-consent');
consent.addEventListener('load', () => console.log('Banner loaded!'));
consent.addEventListener('error', (e) => console.error(e.detail));import { registerTinyConsent, getTinyConsentScriptUrl } from 'tinyconsent-webcomponent';
// Register with custom tag name (optional)
registerTinyConsent('my-cookie-banner');
// Get script URL
const url = getTinyConsentScriptUrl('your-script-id');const consent = document.createElement('tiny-consent');
consent.setAttribute('script-id', 'your-script-id');
document.body.appendChild(consent);<template>
<div>
<tiny-consent script-id="your-script-id"></tiny-consent>
<!-- Your app -->
</div>
</template>
<script setup>
import 'tinyconsent-webcomponent';
</script>// app.module.ts
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import 'tinyconsent-webcomponent';
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
// ...
})
export class AppModule {}<!-- app.component.html -->
<tiny-consent script-id="your-script-id"></tiny-consent><script>
import 'tinyconsent-webcomponent';
</script>
<tiny-consent script-id="your-script-id"></tiny-consent>import { LitElement, html } from 'lit';
import 'tinyconsent-webcomponent';
class MyApp extends LitElement {
render() {
return html`
<tiny-consent script-id="your-script-id"></tiny-consent>
<div>My App</div>
`;
}
}<tiny-consent
script-id="your-script-id"
id="cookie-consent"
></tiny-consent>
<script type="module">
import 'tinyconsent-webcomponent';
const consent = document.getElementById('cookie-consent');
consent.addEventListener('load', () => {
console.log('Cookie banner is ready!');
});
consent.addEventListener('error', (event) => {
console.error('Failed to load banner:', event.detail);
});
</script>A cookie banner handles the consent collection part of privacy compliance:
- Displays a notice about cookies and tracking
- Collects user consent preferences
- Blocks non-essential scripts until consent is given
- Stores consent choices
Cookie consent is just one part of privacy law compliance. Full compliance also includes:
- Privacy Policy - Document explaining your data practices
- Data Processing Records - Internal documentation
- User Rights Handling - Ability to handle data access/deletion requests
- Legal Basis - Proper justification for data processing
TinyConsent helps with cookie consent. For your privacy policy, use: tinyconsent.com/privacy-policy-generator
The GDPR (General Data Protection Regulation) requires:
- Prior consent - Get consent BEFORE setting non-essential cookies
- Informed consent - Tell users what cookies do
- Granular options - Let users choose cookie categories
- Easy withdrawal - Make it easy to change preferences
- No pre-ticked boxes - Consent must be affirmative
Learn more: GDPR Cookie Requirements
The CCPA (California Consumer Privacy Act) requires:
- Notice at collection - Disclose what data you collect
- Opt-out right - "Do Not Sell My Personal Information" option
- Non-discrimination - Can't penalize users who opt out
Learn more: CCPA Cookie Requirements
- Visit tinyconsent.com/cookie-banner-generator
- Enter your email
- Copy your script ID
Yes! Web Components work in any framework: React, Vue, Angular, Svelte, Lit, or plain HTML.
Yes. TinyConsent blocks Google Analytics, Facebook Pixel, and other trackers until the user consents.
Yes. Google Consent Mode is automatically integrated.
Yes! All customization is done in your TinyConsent Dashboard.
Yes, privacy regulations require one. Generate yours: tinyconsent.com/privacy-policy-generator
No. A cookie banner handles consent collection, but full GDPR compliance requires a privacy policy, data processing records, and more. TinyConsent helps with the cookie consent part.
Make sure you import the module before using the element:
<script type="module">
import 'tinyconsent-webcomponent';
</script>- Check your script ID is correct
- Ensure the import is loading (check Network tab)
- Test in incognito mode
- Check browser console for errors
The package includes TypeScript definitions. If you have issues:
/// <reference types="tinyconsent-webcomponent" />Configure your framework to recognize custom elements:
Vue 3:
// vite.config.js
export default {
vue: {
compilerOptions: {
isCustomElement: tag => tag === 'tiny-consent'
}
}
}Angular:
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA]
})Full TypeScript support:
import {
TinyConsentElement,
registerTinyConsent,
getTinyConsentScriptUrl,
TinyConsentAttributes
} from 'tinyconsent-webcomponent';
// Type the element
const element = document.querySelector('tiny-consent') as TinyConsentElement;
console.log(element.loaded); // booleantinyconsent- Vanilla JS/TS loadertinyconsent-react- React component
- Cookie Banner Generator: tinyconsent.com/cookie-banner-generator
- Privacy Policy Generator: tinyconsent.com/privacy-policy-generator
- Dashboard: tinyconsent.com/dashboard
- What is a Cookie Banner?: tinyconsent.com/what-is-a-cookie-banner
- GDPR Guide: tinyconsent.com/gdpr-cookie-requirements
MIT © TinyConsent
Keywords: cookie banner, cookie consent, web component, custom element, GDPR, CCPA, cookie banner generator, cookie consent script, one line cookie banner, lightweight cookie consent, cookie banner npm, vanilla js, framework agnostic, privacy, consent management