CookieConsent <pm-cookie-consent>
Cookie consent: asks the visitor which optional cookies they allow, remembers the answer and tells your code.
Overview
It shows until the visitor chooses, then stays away (the choice is kept in localStorage; change version to ask everyone again after your cookies change). "Accept all" and "Reject all" look the same and sit side by side, nothing optional is switched on beforehand, and the page stays usable while it is shown. Load analytics or marketing scripts only after pm-consent says so, or read the choice with readConsent() on later visits. show() opens it again, for a "Cookie settings" link in the footer.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
open | boolean | false | Shown. Set by the element: open until a choice is stored. |
heading | string | — | Title of the notice (default "Cookies"). |
description | string | — | One or two sentences on what the cookies are for. |
categories | ConsentCategory[] | — | The choices: [{ id, label, description?, required? }]. Default: necessary, analytics, marketing. |
storage-keyprop: storageKey | string | — | Name of the stored choice (default consent). Use the same key on every page of a site. |
version | string | — | Version of your cookie list (default 1). A stored choice of another version is asked again. |
position | 'start' | 'center' | 'end' | — | Corner of the screen: start (default), center or end. |
inline | boolean | false | Stay in the flow of the page instead of floating (for a settings page). |
accept-labelprop: acceptLabel | string | — | Text of the accept button (default "Accept all"). |
reject-labelprop: rejectLabel | string | — | Text of the reject button (default "Reject all"). |
customize-labelprop: customizeLabel | string | — | Text of the button that shows the choices (default "Customize"). |
save-labelprop: saveLabel | string | — | Text of the button that stores the chosen switches (default "Save choices"). |
Also accepts the contextual attributes tone, surface, radius, density, motion, elevation. They are inherited from ancestors' data-* attributes.
Events
| Event | React / Svelte prop | Description |
|---|---|---|
pm-consent | onPmConsent | The visitor chose. detail.choice has one boolean per category; detail.action is accept, reject or save. |
Slots
| Slot | Description |
|---|---|
(default) | The explanation, instead of description. Link to your privacy policy here. |
CSS parts
| Part | Description |
|---|---|
::part(base) | The notice. |
Methods
show(), reset()