Customizing Colours and Fonts
Every colour, font and size in Chapter is a CSS variable, called a design token. Components never use raw values, so changing a token changes the whole site.
The three layers
Tokens live in src/styles/tokens/, in three files:
| File | Holds | Example |
|---|---|---|
primitives.css |
The raw palette | --palette-blue-600: #0066cc; |
semantic.css |
What each colour is for, in light and dark mode | --color-accent: var(--palette-blue-600); |
components.css |
Layout sizes | --rail-left-width, --content-measure |
Components only use the semantic and component layers. To restyle the site, you almost always edit semantic.css, and sometimes add a colour to primitives.css.
Changing the accent colour
The accent colours links, the current chapter, category names and focus rings. It is set once for light mode and once for dark mode:
:root { /* light mode */ --color-accent: var(--palette-green-600);}
html.dark { /* dark mode */ --color-accent: var(--palette-tokyo-green);}Add the colours you reference to primitives.css first:
:root { --palette-green-600: #1a7f37; --palette-tokyo-green: #9ece6a;}Check the contrast of your accent against the background in both modes; links need at least 4.5:1 to stay readable.
Adjusting dark mode
Dark mode is the html.dark block in semantic.css. It redefines the same tokens with the Tokyo Night palette. You can change any of them, for example a slightly lighter background:
html.dark { --color-bg-default: var(--palette-tokyo-bg-surface);}Code blocks follow their own theme (Tokyo Night), set in astro.config.mjs under ExpressiveCode({ themes }). If you change the dark palette a lot, change the code theme to match.
Fonts
Two tokens set the fonts:
--font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Latin Quotes", "PingFang TC", "Noto Sans TC", "Noto Sans TC Variable", system-ui, sans-serif;--font-mono: "JetBrains Mono", "JetBrains Mono Variable", ui-monospace, SFMono-Regular, Menlo, monospace;Apple devices use their system fonts. Elsewhere, Noto Sans TC and JetBrains Mono are loaded from the site itself, imported in src/components/BaseHead.astro. To use another font, install it from Fontsource, import it there and put its name first in the token.
Writing mostly in Japanese or Simplified Chinese? Swap Noto Sans TC for @fontsource-variable/noto-sans-jp or noto-sans-sc so the right glyph shapes are used.
Tests keep the layers honest
pnpm test checks the token rules: every colour exists in both light and dark mode, components do not hard-code colours, and every variable Tailwind refers to exists. If you add a semantic colour to light mode and forget dark mode, the test tells you before a visitor does.