Skip to content

Custom Font

Load your brand font via a self-hosted @font-face declaration and apply it to the entire banner with a single token override.

Replace Kookiok’s default system-font stack with a custom typeface — matching your website’s visual identity. This recipe uses a self-hosted font to avoid sending visitor IP addresses to third-party CDNs (a GDPR requirement under EU court rulings).

custom.css
/* ── Self-hosted brand font ────────────────────────────── */
/*
1. Upload your font files to your own server or CDN.
2. Replace the src URLs below with your actual paths.
3. Repeat the @font-face block for each weight you need.
*/
@font-face {
font-family: 'BrandSans';
src: url('https://cdn.example.com/fonts/BrandSans-Regular.woff2') format('woff2'),
url('https://cdn.example.com/fonts/BrandSans-Regular.woff') format('woff');
font-weight: 400;
font-style: normal;
font-display: swap;
}
@font-face {
font-family: 'BrandSans';
src: url('https://cdn.example.com/fonts/BrandSans-SemiBold.woff2') format('woff2'),
url('https://cdn.example.com/fonts/BrandSans-SemiBold.woff') format('woff');
font-weight: 600;
font-style: normal;
font-display: swap;
}
/* Apply to the banner via token override */
.ag-banner {
--font-family: 'BrandSans', system-ui, sans-serif;
}
classic · dialog · center

(The preview above uses the visitor’s local Georgia — a system serif — to demonstrate the token mechanism without loading any external font.)

  • @font-face declares the typeface inside the Shadow DOM scope. Because the Kookiok banner lives in a Shadow DOM, fonts must be declared either inside the custom CSS block or be already loaded on the host page (host fonts are inherited into shadow trees by browsers).
  • font-display: swap ensures the banner text is visible immediately using a fallback font, then swaps in the brand font once it downloads — no invisible-text flash.
  • --font-family is the single token that all text elements inside .ag-banner read. Setting it propagates to headings, body copy, button labels, and legal text.
  • The fallback stack (system-ui, sans-serif) activates if the font file fails to load, keeping the banner legible.

To self-host a Google Font:

  1. Go to google-webfonts-helper.herokuapp.com — an open-source tool that packages Google Fonts for self-hosting.
  2. Select your font, choose the weights and subsets you need.
  3. Download the .woff2 + .woff package.
  4. Upload the files to your own server (e.g. https://cdn.example.com/fonts/).
  5. Copy the generated @font-face CSS and replace the src URLs with your file paths.

Alternatively, use a package manager: many fonts are available via npm (e.g. @fontsource/inter). Bundle the .woff2 files as static assets and reference them via an absolute URL.

Monospace for a technical brand:

@font-face {
font-family: 'JetBrainsMono';
src: url('https://cdn.example.com/fonts/JetBrainsMono-Regular.woff2') format('woff2');
font-weight: 400;
font-display: swap;
}
.ag-banner {
--font-family: 'JetBrainsMono', 'Courier New', monospace;
}

Using a font already loaded on the host page. If your website already loads the font (e.g. via a <link> in <head>), browsers allow Shadow DOM to inherit it — skip @font-face entirely:

.ag-banner {
/* Inherits from host page's already-loaded font */
--font-family: 'MyPageFont', system-ui, sans-serif;
}

Serif for a luxury / editorial brand:

.ag-banner {
--font-family: 'Playfair Display', Georgia, serif;
}

Serving font files from your own domain means no third-party network requests are made when the banner loads. This keeps the banner within the GDPR legal basis for essential cookies/session data only, with no external disclosures.

Ensure your web server sends appropriate Cache-Control headers for font files (e.g. max-age=31536000, immutable) to avoid repeat downloads on subsequent page views.

  • Brand Colors — pair a custom font with a matching palette
  • Full Redesign — see font customization in a complete restyle
  • Shadow DOM — understand why fonts must be declared inside the custom CSS block