---
title: "Script and element attributes"
description: "Reference for every data attribute the CookieBeam runtime reads from your markup, covering script gating, consent actions, and modal controls."
url: "https://cookiebeam.com/docs/api-reference/script-attributes"
lang: "en"
last_updated: "2026-11-16"
---

# Script and element attributes

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

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.

| Attribute | Default value | Configurable via | What it does |
| --- | --- | --- | --- |
| `data-category` | `data-category` | `scriptGating.dataAttributeName` | Names 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-src` | `data-src` | `scriptGating.srcAttributeName` | Holds the real script URL. On activation, this value moves to `src` and the browser fetches it |
| `type="text/plain"` | `text/plain` | `scriptGating.placeholderTypeValue` | Prevents 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](https://cookiebeam.com/docs/api-reference/config-reference#scriptgating). The defaults work for the vast majority of setups.

### Basic script gating

```html
<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`:

```html
<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:

```html
<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](https://cookiebeam.com/docs/configure/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 field | Default | What it renames |
| --- | --- | --- |
| `dataAttributeName` | `data-category` | The category attribute the runtime looks for |
| `placeholderTypeValue` | `text/plain` | The `type` value that marks a script as blocked |
| `srcAttributeName` | `data-src` | The attribute holding the real URL |

See [Configuration reference: scriptGating](https://cookiebeam.com/docs/api-reference/config-reference#scriptgating).

## Consent action attributes

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

| Value | Action |
| --- | --- |
| `show-preferencesModal` | Open the preferences modal |
| `show-consentModal` | Show the consent banner |
| `accept-all` | Accept every category |
| `accept-necessary` | Accept only the necessary (read-only) categories |
| `accept-custom` | Accept 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:

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

A button that accepts only analytics and preferences:

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

A footer link that reopens the consent banner:

```html
<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:

| Value | Action |
| --- | --- |
| `close-usOptOutPanel` | Close the US opt-out panel |
| `us-confirm` | Confirm 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.

| Attribute | Found on | Values | Purpose |
| --- | --- | --- | --- |
| `data-cb-modal` | Modal container elements | `consentModal`, `preferencesModal` | Identifies which modal the element belongs to |
| `data-cb-replaces-desc` | TCF 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:

```css
[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.

### Consent modal (`cb-cm`)

| Class | Element |
| --- | --- |
| `cb-cm__root` | Root container (on the outermost wrapper, alongside `cb-root`) |
| `cb-cm__title` | Title text |
| `cb-cm__description` | Description text |
| `cb-cm__btns` | Button row |
| `cb-cm__btn` | Any button |
| `cb-cm__btn--primary` | Primary action button |
| `cb-cm__btn--secondary` | Secondary action button |
| `cb-cm__btn--tertiary` | Tertiary action button |
| `cb-cm__footer` | Footer row |

### Preferences modal (`cb-pm`)

| Class | Element |
| --- | --- |
| `cb-pm__root` | Root container (on the outermost wrapper, alongside `cb-root`) |
| `cb-pm__header` | Header area |
| `cb-pm__title` | Title text |
| `cb-pm__body` | Scrollable content area |
| `cb-pm__section` | Category section |
| `cb-pm__toggle` | Consent toggle |
| `cb-pm__service` | Service toggle row |
| `cb-pm__close-btn` | Close button (when enabled) |
| `cb-pm__footer` | Footer area |

### Other elements

| Class | Element |
| --- | --- |
| `cb-settings-btn` | Floating settings button |
| `cb-overlay` | Background overlay / backdrop |
| `cb--checkboxes` | Added 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](https://cookiebeam.com/docs/configure/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:

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

## Next steps

- [Blocking](https://cookiebeam.com/docs/configure/blocking) explains how automatic and manual script gating work together
- [Browser API](https://cookiebeam.com/docs/api-reference/browser-api) covers the JavaScript API for programmatic consent control
- [Configuration reference](https://cookiebeam.com/docs/api-reference/config-reference#scriptgating) documents the `scriptGating` config fields
