Theme Contract
The Theme Contract is the formal spec every Groundwork theme has to satisfy: the required-tokens table, accessible contrast pairings checked against real WCAG thresholds, and the fixed light/dark cascade order that decides a token's final value. It's public and versioned, the way a WordPress or Shopify theme has a documented structure. If installing a theme means editing cart, search or routing logic, it isn't a theme by this definition.
This doc is for anyone building a theme on top of Groundwork, from adjusting the included themes to writing a new one. Afterwards you'll know which CSS custom properties a theme must define, which contrast pairings need re-checking if you change an accent color, and why the cascade order (root → prefers-color-scheme → data-theme override) can't be skipped or reordered.
Before you start: read the theming section of Architecture, which covers the same token layer in summary before this doc goes into the full spec.
Related: Overview for how tokens map into Tailwind's @theme namespace, and Testing for how the accessibility suite (axe-core) catches a contrast regression if a theme swaps in a value that doesn't clear the documented threshold.
Source: docs/THEME_CONTRACT.md
This is the spec a theme must satisfy to install cleanly. That applies to the included Barebones and Signal themes and to any theme built after them. It exists because the whole point of separating logic from presentation (see ARCHITECTURE.md) is that a theme drops in without forking the codebase. If installing a theme means editing cart, search, filtering, or routing logic, it isn't a theme by this template's definition.
Treat this document as versioned and public-facing, the same way a WordPress or Shopify theme has a documented structure. Breaking changes to the contract bump the version at the top of this file.
1. Token layer
All visual values a theme is allowed to change live in app/styles/tokens.css as CSS custom properties, prefixed --sb- to stay visually distinct from Tailwind's own generated scale and from any one-off variable a theme adds later. Nothing outside this file should declare a new --sb-color-*, --sb-space-*, --sb-radius-*, --sb-shadow-*, or --sb-font-* token. Extend the existing set there instead, so every theme and every component draws from the same source of truth.
Required tokens
Every theme must provide a value (light and dark) for these. Components in app/components/ are only allowed to reach for tokens in this list. If a component needs something that isn't on it, the token gets added here first; it never gets hardcoded in the component.
| Token | Purpose |
|---|---|
--sb-color-bg | Page background |
--sb-color-fg | Default text color |
--sb-color-surface | Card/panel background (asides, dropdowns) |
--sb-color-surface-2 | A step above surface: subtle contrast (e.g. the theme toggle's track) |
--sb-color-border | Dividers, input borders, panel edges |
--sb-color-muted-fg | Secondary/help text |
--sb-color-accent | Primary action color (buttons, active states, links) |
--sb-color-accent-fg | Text/icon color on top of accent |
--sb-color-danger | Errors, destructive actions |
--sb-color-success | Confirmations, in-stock indicators |
--sb-font-sans | Base font stack |
--sb-font-size-xs … --sb-font-size-3xl | Type scale |
--sb-space-1 … --sb-space-16 | Spacing scale |
--sb-radius-sm / -md / -lg / -full | Border radii |
--sb-shadow-sm / -md / -lg | Elevation |
Accessible contrast pairings
--sb-color-accent is documented above as usable for links and text as well as button backgrounds, so it's worth being explicit about where that's safe. In the shipped Signal palette, --sb-color-accent-text scores 6.69:1 (light) / 8.44:1 (dark) against --sb-color-surface, and 5.67:1 (light) / 7.62:1 (dark) against --sb-color-surface-2. That's AA for normal-sized text in every combination the template renders.
That second pairing used to be the tight one. Under the previous violet palette it measured 4.40:1, just under the 4.5:1 threshold, and this section warned that no shipped component happened to place accent text on surface-2 but that one easily could. The brass accent clears it with room in both themes, so the near-miss is gone. The rule that produced the warning still stands, though: if a theme redefines --sb-color-accent or --sb-color-accent-text, re-measure both pairings. --sb-color-accent as a background with --sb-color-accent-fg as text is a separate case; that pair needs to clear 4.5:1 as text on a fill (it scores 5.81:1 light / 6.81:1 dark), while the fill itself only needs 3:1 as a UI component.
--sb-color-danger is used the same way in three places (.product-low-stock, .search-page-error, .notify-back-in-stock-error): plain text directly on --sb-color-bg, never as a background fill. So it needs the full 4.5:1 text threshold against --sb-color-bg. The 3:1 a badge or icon fill would get doesn't apply. The shipped values score 5.52:1 (light, --sb-red-700) and 5.92:1 (dark, --sb-red-400). axe-core's e2e coverage (e2e/accessibility.spec.ts) runs over every marketing route in both themes and is what would catch a regression if a theme swaps in a lighter red without re-checking this.
A note on how the shipped themes are built, because it affects how you should build yours: neither one is an inversion of the other. The dark theme is a cyanotype, all cool Prussian blue-blacks, and the light theme is drafting vellum, a warm paper with blue-black ink. They satisfy the same contract from different directions. A theme is free to be symmetrical instead. The contract cares about the required tokens and the measured pairings, and it has no opinion on temperature.
Optional tokens
A theme may add tokens beyond this list (e.g. a decorative gradient, a second accent color for a sale badge), but they must not be required by any component that ships in this template. Optional tokens are for a theme's own bespoke sections. The shared component library never depends on them.
Light/dark resolution order
Values cascade in this order (each step overrides the previous):
:root: light values (default).@media (prefers-color-scheme: dark): dark values, applied automatically when the OS asks for it.:root[data-theme="light"]/:root[data-theme="dark"]: an explicit user override, set via the cookie described below. Because attribute selectors are more specific than a plain:rootinside a media query, step 3 always wins over step 2 regardless of source order.
app/root.tsx reads the override cookie during the SSR loader (getThemeFromRequest, in app/lib/theme.ts) and sets data-theme on <html> before any markup reaches the browser. There is no client-side check-and-swap, so there's no flash of the wrong theme on load. A theme must not reintroduce one (e.g. by reading localStorage in an effect and swapping classes after mount).
2. Tailwind mapping
app/styles/tailwind.css maps the required color/font/spacing/radius/shadow tokens above into Tailwind's @theme namespace, so bg-surface, text-muted-fg, rounded-md, shadow-lg, etc. resolve to the exact same values a non-Tailwind theme gets from var(--sb-color-surface) directly. A theme that uses Tailwind utilities and a theme that writes plain CSS against the --sb-* variables are equally first-class. Pick whichever fits the theme, but don't invent a third naming scheme for the same values.
3. Component slots
Components in app/components/ render logic-driven structure (cart lines, search results, product options) but must not hardcode colors, spacing, or radii outside the token list above. A theme's presentation layer is expected to style these components via the class names they already render (e.g. .cart-line, .product-options-item) or via the tokens they consume. They should never branch component code on which theme is active.
A theme covers both modes. Light and dark aren't two separate themes. They're the two modes every theme has to define, which is what section 1's light/dark resolution order is for. Signal, the theme this template ships and the one shopgroundwork.com runs on, is a cyanotype dark mode and a drafting-vellum light mode: one theme, one token file, two modes. A "theme" that only defined one of them could not satisfy this contract.
This template does not yet ship a formal slot/override API (e.g. a themeOverrides prop). That's intentionally deferred until Barebones is built alongside Signal (see ARCHITECTURE.md and the build order in the product spec), so the slot boundaries are informed by two real themes instead of guessed at up front. Until then, "theme = tokens + CSS," and if a component can't be reskinned by tokens alone, the bug is in the component. The contract has no gap there.
4. What's not covered yet
- Per-component override props/slots (deferred until Barebones is built alongside Signal, see above).
- A packaged way to swap themes at the project level (config value + token file, per the product spec). Signal is built (it's what
tokens.cssdefines), so v1 ships exactly one token file. Barebones' tokens will live alongside it, at which point this section will document the actual swap mechanism instead of the intended one.