Custom Font
Load your brand font via a self-hosted
@font-facedeclaration 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).
The CSS
Section titled “The 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;}Live preview
Section titled “Live preview”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.)
What’s happening
Section titled “What’s happening”@font-facedeclares 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: swapensures the banner text is visible immediately using a fallback font, then swaps in the brand font once it downloads — no invisible-text flash.--font-familyis the single token that all text elements inside.ag-bannerread. 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.
Self-hosting a Google font (step-by-step)
Section titled “Self-hosting a Google font (step-by-step)”To self-host a Google Font:
- Go to google-webfonts-helper.herokuapp.com — an open-source tool that packages Google Fonts for self-hosting.
- Select your font, choose the weights and subsets you need.
- Download the
.woff2+.woffpackage. - Upload the files to your own server (e.g.
https://cdn.example.com/fonts/). - Copy the generated
@font-faceCSS and replace thesrcURLs 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.
Variations
Section titled “Variations”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;}Compliance notes
Section titled “Compliance notes”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.
Related recipes
Section titled “Related recipes”- 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