How Custom CSS Works — Shadow DOM
Shadow DOM creates a hard CSS boundary between the banner and your site. Your site cannot accidentally style the banner, and the banner cannot accidentally style your site.
What is Shadow DOM?
Section titled “What is Shadow DOM?”Shadow DOM is a W3C web standard that lets a component own a private document subtree — its own DOM and CSS scope — attached to a regular element called the shadow host. Styles inside a Shadow Root do not leak out; styles outside do not leak in.
Kookiok attaches a Shadow Root to:
<div id="__AG_CONSENT_HOST__"></div>This element is injected into <body> by consent.js. All banner HTML lives inside its Shadow Root.
Since v2026.08.04 your custom CSS is injected into three Shadow Roots, not one: the banner, the floating privacy trigger (#ag-privacy-trigger), and the preferences popup (#ag-privacy-popup-host). Each is a separate isolation boundary, so a selector only matches inside the root that contains it — .ag-banner rules never reach the popup, and .ag-popup-* rules never reach the banner. :host { } token overrides are applied per root, which is why one token block themes all three surfaces consistently. See the Customization Guide for the full scoping rules.
Why we use it
Section titled “Why we use it”| Problem without Shadow DOM | How Shadow DOM solves it |
|---|---|
Site’s button {} rule restyling banner buttons | Shadow boundary blocks external selectors |
Banner’s * { box-sizing: border-box } breaking site layout | Shadow boundary blocks internal selectors from escaping |
Branding hidden by .hidden { display: none } on the host page | External selectors cannot pierce the Shadow Root |
Site’s :root CSS vars changing banner colors | CSS vars do pierce the Shadow Root — intentional for token inheritance |
What CSS works inside the Shadow Root
Section titled “What CSS works inside the Shadow Root”Works normally:
- All standard CSS selectors (class, id, attribute, pseudo-class, pseudo-element)
- CSS custom properties (variables) — they inherit through Shadow DOM
@mediaqueries@keyframesanimations:focus-visible,:hover,:checkedpseudo-classes
Does not work:
- External
@font-facerules — fonts must be declared inside the Shadow Root or the host page must load them first @import— blocked by the sanitizer (also a CSP concern)- Selectors targeting elements outside the Shadow Root (e.g.,
body,html)
Special selector — :host:
The :host pseudo-class selects the shadow host element itself. This is where you declare CSS custom property overrides:
:host { --surface: #1a1a2e; --radius: 4px;}Putting overrides on :host means they cascade down to all banner elements that consume those tokens, with a single declaration point.
Debugging with DevTools
Section titled “Debugging with DevTools”To inspect banner styles in Chrome or Firefox DevTools:
- Open DevTools → Elements panel.
- Locate
<div id="__AG_CONSENT_HOST__">in the DOM tree. - Click the ▶ (expand) arrow — you will see
#shadow-root (open). - Expand the shadow root to browse
.ag-overlay,.ag-banner, etc. - The Styles panel in DevTools shows styles applied inside the Shadow Root, including which custom CSS rule is winning.
CSS custom properties pierce the boundary
Section titled “CSS custom properties pierce the boundary”One important nuance: CSS custom properties (variables) do inherit across Shadow DOM boundaries. This means:
/* On your page's :root */:root { --primary: #6366f1;}If the banner uses var(--primary) anywhere, it will pick up this value. Kookiok’s tokens are all prefixed with --surface-*, --btn-*, --accent-*, etc. to avoid accidental collisions with your site’s own CSS variables.
Font loading note
Section titled “Font loading note”Custom fonts must be loaded before the banner renders, either:
- Via a
<link>in your<head>pointing to a self-hosted font file (no Google Fonts CDN — see GDPR memory), or - Via
@font-facein your page CSS.
Then in your custom CSS banner snippet, reference the font family:
:host { --font-family: "My Brand Font", system-ui, sans-serif;}The Shadow DOM will pick up fonts loaded by the host page.