Skip to content

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.

  • 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.
  • 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.
  1. From the app’s project root:

    Terminal window
    npx canvas pull

    The command writes the Brand Kit colors and fonts to canvas.brand-kit.json and downloads the font files into fonts/:

    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 pull also brings code components, the global CSS file at globalCssPath, package dependencies, and, unless canvas.config.json turns them off, pages and templates. It can also offer to delete local components that aren’t on the site. Review the result with git diff and keep only canvas.brand-kit.json and fonts/.

  2. Each key in colors is a CSS variable name without its leading --. The value is either the color itself or, in the object form, its value. Add them to :root in your app’s global CSS, for example app/globals.css in 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.

  3. 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 src in canvas.brand-kit.json is a file path in your project; the url() in CSS is the URL your app serves the file at. Use name as the font-family, and the entry’s weights and styles for font-weight and font-style.

  4. 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-red and font-brand.

  5. 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.json to its preview by itself, so a correct Workbench preview doesn’t show that your app’s CSS defines them.

  6. 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-red from the brand-red key in canvas.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 push skips the Brand Kit when the file is missing, and canvas pull writes it again unless you pass --no-include-brand-kit.

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.