Theming & fonts

Colours and fonts are content. Rebranding a site is editing, not refactoring.

Colours are documents

A colour theme is a Sanity document with a background, a text colour, and an optional accent. A build step reads those documents and writes a CSS variable file; components reference variable names. There are no hex codes in Vue files.

The consequence is the point: a client rebrand is content editing, not a refactor. Change the theme document, rebuild, done. Pages can carry their own theme, and individual sections can override it.

Changing the brand

  1. Edit the colour theme in the Studio

    Website → Colours. Set the background, text and accent. Optionally setdark-scheme counterparts — an empty dark slot reuses the light colour, so atheme with no dark colours looks the same in both schemes.

  2. Regenerate the variables

    Shell
    defineField({
        name: 'heading',
        title: 'Heading',
        type: 'string',
        validation: (rule) => rule.required(),
        group: 'general',
    }),

    This runs automatically on npm run dev and as part of the build, so in practice you only run it by hand after editing colours in a running session.

  3. Set the fonts

    Fonts are declared in fonts.js and compiled in the same way.

    Shell
    <script setup lang="ts">
    import type { CustomHero, ComponentProps } from '~~/types'
    
    interface Props extends ComponentProps<CustomHero> {}
    const props = defineProps<Props>()
    </script>

Light and dark

The colour scheme is resolved at _build_ time, not render time. The generator emits every scheme-dependent value under the same variable names in each scheme's block, so switching schemes is a plain CSS cascade override, and no component needs changing.

This matters more than it sounds on a prerendered site. The server cannot know a visitor's colour scheme, so anything scheme-dependent in rendered markup — a class, an attribute, an inline style — hydrates differently than it rendered. Keeping the decision in CSS is what makes the feature safe.

Derived colours are derived at build time too: accent hover states, outline borders, elevated surfaces, gradient stops. Adding a new scheme-dependent colour means adding a variable to the generator, not a branch in a component.

SurfaceControlled by
Site defaultSite settings → theme
A pageThe page's own colour options
A sectionSection options → theme
Navigation barNavigation config, with a per-page override
FooterFooter config, with a per-page override
Form inputsForm block's input theme, defaulting to the page theme
Code blocksInherit the page theme, or use Shiki's palette