Passer au contenu de la documentation

Script and element attributes

Reference for every data attribute the CookieBeam runtime reads from your markup, covering script gating, consent actions, and modal controls.

Dernière mise à jour:

The CookieBeam runtime reads specific HTML attributes to decide which scripts to block, which to activate, and what happens when a visitor clicks a consent control. This page lists every attribute the runtime looks for, grouped by purpose.

Script gating attributes

These attributes go on <script> elements you want CookieBeam to hold back until the visitor consents. The runtime scans the page for elements matching the gating selector and activates them when the right categories are accepted.

AttributeDefault valueConfigurable viaWhat it does
data-categorydata-categoryscriptGating.dataAttributeNameNames the single consent category that must be accepted before the script runs. The value is matched as one category name (commas are not split)
data-srcdata-srcscriptGating.srcAttributeNameHolds the real script URL. On activation, this value moves to src and the browser fetches it
type="text/plain"text/plainscriptGating.placeholderTypeValuePrevents the browser from executing the script. The runtime clones the element with the correct type on activation
data-categories--Used on data-cb="accept-custom" buttons to list categories the button accepts (comma-separated). Not an alias for data-category on script elements
data-cookiebeam-run-on-disable--Fires the script when its category is denied, not when it's accepted. Used for opt-out beacons
data-purpose--Purpose-level gating for banners with the purpose consent feature enabled
data-cookieblock-src--Internal: automatic blocking moves a script's original src here. Don't set this yourself

The first three attributes have configurable names via scriptGating in the configuration reference. The defaults work for the vast majority of setups.

Basic script gating

<script type="text/plain" data-category="analytics" data-src="https://example.com/analytics.js"></script>

The browser ignores the script (its type isn't executable). When the visitor accepts the analytics category, CookieBeam clones the element without the type attribute (so the browser uses its default executable type) and with src set to the URL from data-src. If the original had a data-type attribute, that value becomes the clone's type. The runtime clones rather than mutating the original because changing type on an existing <script> doesn't trigger execution in browsers.

Inline script gating

Inline scripts don't need data-src:

<script type="text/plain" data-category="analytics">
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
</script>

Run-on-disable (opt-out beacons)

Some vendors expect an explicit "the user opted out" signal. Mark the script with data-cookiebeam-run-on-disable and it fires when its category is denied in any valid consent record:

<script type="text/plain" data-category="analytics" data-cookiebeam-run-on-disable="true" data-src="https://example.com/opt-out-beacon.js"></script>

Firing rules:

  • A valid consent record must exist. In opt-out or notice mode, the machine-written default is already valid, so the script can fire on first page load, before the visitor touches the banner.
  • Fires once per page load. A toggle-off → toggle-on → toggle-off cycle in the same page view fires it only once; a navigation or reload resets the counter.
  • The attribute value doesn't matter; its presence is enough (though "true" works and reads clearly). The only value that suppresses it is "false".

See Blocking: run-on-disable scripts for the full behavior.

Auto-blocking internal attribute

When automatic blocking intercepts a third-party script (one the scanner classified), it moves the original src to data-cookieblock-src and blanks the real src. You'll see this in the DOM inspector on blocked scripts, but don't set it in your own markup. The runtime manages it.

Customizing attribute names

The scriptGating configuration lets you rename the three core gating attributes:

Config fieldDefaultWhat it renames
dataAttributeNamedata-categoryThe category attribute the runtime looks for
placeholderTypeValuetext/plainThe type value that marks a script as blocked
srcAttributeNamedata-srcThe attribute holding the real URL

See Configuration reference: scriptGating.

Put a data-cb attribute on any clickable element to turn it into a consent control. The runtime intercepts clicks and performs the action; no JavaScript required.

data-cb values

ValueAction
show-preferencesModalOpen the preferences modal
show-consentModalShow the consent banner
accept-allAccept every category
accept-necessaryAccept only the necessary (read-only) categories
accept-customAccept the categories listed in the element's data-categories or data-category attribute

For accept-custom, the element must also carry data-categories (or data-category) with a comma-separated list of category IDs.

data-cc (legacy alias)

data-cc accepts all the same values as data-cb and behaves identically. It exists for pages built against older banner scripts. New markup should use data-cb.

Examples

A "Cookie settings" link anywhere on your page:

<a href="#" data-cb="show-preferencesModal">Cookie settings</a>

A button that accepts only analytics and preferences:

<button type="button" data-cb="accept-custom" data-categories="analytics,preferences">
  Allow analytics only
</button>

A footer link that reopens the consent banner:

<a href="#" data-cb="show-consentModal">Manage cookies</a>

Internal action values

The runtime uses these values on buttons it renders inside the banner. They are for internal use and don't work on your own site elements:

ValueAction
close-usOptOutPanelClose the US opt-out panel
us-confirmConfirm choices in the US opt-out panel

Internal DOM attributes

These attributes are set by the runtime on elements it creates. They aren't meant for your markup, but they're useful for CSS targeting and DOM inspection.

AttributeFound onValuesPurpose
data-cb-modalModal container elementsconsentModal, preferencesModalIdentifies which modal the element belongs to
data-cb-replaces-descTCF disclosure element-Marks the TCF first-layer disclosure that replaces the consent modal description

Targeting modals in CSS

The modal attribute is useful for custom CSS that styles one modal differently from the other:

[data-cb-modal="consentModal"] .cb-cm__btn--primary {
  /* Style the primary button only in the consent banner */
}

CSS class reference

The runtime uses a consistent class naming scheme. These classes are stable across versions and safe to use in custom CSS selectors.

ClassElement
cb-cm__rootRoot container (on the outermost wrapper, alongside cb-root)
cb-cm__titleTitle text
cb-cm__descriptionDescription text
cb-cm__btnsButton row
cb-cm__btnAny button
cb-cm__btn--primaryPrimary action button
cb-cm__btn--secondarySecondary action button
cb-cm__btn--tertiaryTertiary action button
cb-cm__footerFooter row

Preferences modal (cb-pm)

ClassElement
cb-pm__rootRoot container (on the outermost wrapper, alongside cb-root)
cb-pm__headerHeader area
cb-pm__titleTitle text
cb-pm__bodyScrollable content area
cb-pm__sectionCategory section
cb-pm__toggleConsent toggle
cb-pm__serviceService toggle row
cb-pm__close-btnClose button (when enabled)
cb-pm__footerFooter area

Other elements

ClassElement
cb-settings-btnFloating settings button
cb-overlayBackground overlay / backdrop
cb--checkboxesAdded to the root when controlStyle is checkbox instead of toggle
cb-us-privacy-link"Do Not Sell or Share" link

CSS custom properties

All design tokens use the --cb- prefix (e.g. --cb-bg, --cb-btn-primary-bg). The legacy --cc- prefix is also read for backward compatibility. See Appearance for the full theming system.

Root container

The runtime mounts all banner DOM inside a <div> with the ID cb-main. This is the outermost container for all consent UI. Use it as a scoping selector when your site's styles conflict with the banner:

#cb-main .cb-cm__title {
  /* Override only inside CookieBeam's container */
}

Next steps