Headless - Brand Kit
The goal of this page: move the colors and fonts from your site’s Brand Kit into your headless frontend app, once, so the app renders them on its own.
When Drupal renders a page, Canvas adds a stylesheet generated from the Brand
Kit: a CSS custom property for each color and an @font-face rule for each
font. A headless app doesn’t receive that stylesheet. Copy the Brand Kit into
the app’s own CSS, and from then on the app owns those styles.
What you’ll have when you’re done
Section titled “What you’ll have when you’re done”- Each Brand Kit color defined in your app’s global CSS, under the same CSS variable name the Brand Kit uses.
- The Brand Kit fonts served by your app and declared with
@font-face. - Optionally, Tailwind CSS utilities for the copied colors and fonts.
Prerequisites
Section titled “Prerequisites”- A frontend app connected to Canvas, as described in Setup.
- The Canvas CLI authenticated against your site. See Local codebase.
- Your app’s changes committed, so you can review what the pull changes.
-
Pull the Brand Kit
Section titled “Pull the Brand Kit”From the app’s project root:
Terminal window npx canvas pullThe command writes the Brand Kit colors and fonts to
canvas.brand-kit.jsonand downloads the font files intofonts/:canvas.brand-kit.json {"fonts": {"families": [{"name": "Brand Sans","src": "fonts/brand-sans-400-normal.woff2","weights": ["400"],"styles": ["normal"]}]},"colors": {"brand-red": "#cc0000","deep-sea": {"value": "#003366","name": "Ocean Deep"}}}canvas pullalso brings code components, the global CSS file atglobalCssPath, package dependencies, and, unlesscanvas.config.jsonturns them off, pages and templates. It can also offer to delete local components that aren’t on the site. Review the result withgit diffand keep onlycanvas.brand-kit.jsonandfonts/. -
Define the colors
Section titled “Define the colors”Each key in
colorsis a CSS variable name without its leading--. The value is either the color itself or, in the object form, itsvalue. Add them to:rootin your app’s global CSS, for exampleapp/globals.cssin the Next.js template:app/globals.css :root {--brand-red: #cc0000;--deep-sea: #003366;}Keep the variable names exactly as in the file. Pages built with the Brand Kit store colors by reference, and a component can render them as
var(--brand-red), which only resolves when your app defines the variable. -
Serve the fonts
Section titled “Serve the fonts”Move the downloaded files into your app’s static directory, for example
public/fonts/, and declare each variant with@font-face:app/globals.css @font-face {font-family: 'Brand Sans';src: url('/fonts/brand-sans-400-normal.woff2') format('woff2');font-weight: 400;font-style: normal;font-display: swap;}The
srcincanvas.brand-kit.jsonis a file path in your project; theurl()in CSS is the URL your app serves the file at. Usenameas thefont-family, and the entry’sweightsandstylesforfont-weightandfont-style. -
Map them to Tailwind CSS (optional)
Section titled “Map them to Tailwind CSS (optional)”If your app uses Tailwind CSS 4, expose the variables as theme tokens with
@theme inline:app/globals.css @theme inline {--color-brand-red: var(--brand-red);--color-deep-sea: var(--deep-sea);--font-brand: 'Brand Sans', sans-serif;}Components can then use utilities such as
bg-brand-redandfont-brand. -
Check the result
Section titled “Check the result”Open a page that uses Brand Kit colors in the Canvas editor, then open its published URL on your app. Both render through your app, so both should show the colors and fonts.
Workbench adds the colors from
canvas.brand-kit.jsonto its preview by itself, so a correct Workbench preview doesn’t show that your app’s CSS defines them. -
Remove
Section titled “Remove canvas.brand-kit.json (optional)”canvas.brand-kit.json(optional)Once the app renders the colors and fonts, the app may no longer need
canvas.brand-kit.json. If none of the local references described below need it, delete it and commit the deletion with your CSS changes, so Workbench stops adding the Brand Kit colors to its preview.Keep the file if local Workbench mocks or page-spec JSON files in your project use Brand Kit color references, for example a mock in
mocks.json:mocks.json [{"name": "Brand background","props": { "backgroundColor": "canvas-color:brand-red" }}]Workbench resolves
canvas-color:brand-redfrom thebrand-redkey incanvas.brand-kit.json, for props declared as colors. Pages your app fetches from Drupal don’t need the file: Drupal resolves their colors.Deleting the file doesn’t change the Brand Kit in Drupal, or the colors that pages reference.
canvas pushskips the Brand Kit when the file is missing, andcanvas pullwrites it again unless you pass--no-include-brand-kit.
After the transfer
Section titled “After the transfer”The app now owns the CSS and font files you copied. Change them in the app; later edits to the Brand Kit in Drupal don’t update them, and editing them doesn’t change the Brand Kit.
Copying the CSS doesn’t disconnect content from the Brand Kit in Drupal. Color props set to a Brand Kit color still reference it, and Drupal resolves the reference to the color’s current value. Whether your component follows that value or your copied CSS depends on which key it reads; see Color props.