Colours, tokens, light and dark

How Goop's colours work: one set of design tokens as CSS variables, light and dark values for each, one brand colour, and Tailwind names that read them.

3 min readMarkdown
theme trail
Light or dark
Accent colour
Density
Pick a colour, drag the corners, change the density or switch to dark: every part that uses the token follows.

Every colour, corner and text size in a Goop theme is a design token: a named value, kept once, in one stylesheet, as a CSS variable. The parts never carry a colour of their own; they read the tokens. Change a token, and every part that uses it follows, in light and in dark.

Light and dark

Every colour token has a light value and a dark value. The page is dark when its <html> element has the class dark, and light otherwise; nothing else switches it. So a part never needs a dark version of its own.

Every Goop theme comes with the switch: a button that flips between light and dark, a menu with System, Light and Dark, and a hook for a control of your own. A short script in the page's head opens the page in the mode the reader chose last time, without a flash of the other one.

  1. Open your coding agent in your project.
  2. Paste this:

Add Goop's light and dark switch to this app's top bar, and open the app in the mode the reader chose last time.

Hand this to your agent
What you'll see
A light and dark switch in the top bar
  • Every part changes with it
  • The app opens in the reader's last choice
Show the exact code

The switch is ColorModeToggle, ColorModeMenu (System, Light, Dark) or useColorMode(), from the theme's own folder (Trail's: @/components/ui/goop/trail/color-mode-toggle). The script for the page's <head>:

HTML
<script>
  try { var colorMode = localStorage.getItem('theme'); } catch (e) {}
  document.documentElement.classList.toggle('dark', colorMode === 'dark' ||
    (colorMode !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches));
</script>

The names

Every theme's colours carry the names shadcn/ui uses, so an agent that knows those knows these: background and foreground, card, popover, primary, secondary, muted, accent, destructive, border, input, ring, five chart colours and the sidebar's own set. Each theme adds a few of its own; Trail's are success, warning and info, a link colour, stronger and fainter text and lines, tints for a hovered or selected row, and soft fills for status badges. Trail has about 70 colour tokens in all, each with its light and its dark value.

Tailwind CSS reads them by the same names, so a class names a token, never a colour: bg-primary, text-muted-foreground, border-border. The corners, text sizes, shadows and control heights are tokens the same way: rounded-lg, text-sm, h-control-md.

The brand colour

The accent is one token, primary: accent buttons, links, focus rings, checked and selected states. Its hover, the link colour and a checkbox's hover edge are worked out from it, in light and in dark. (A browser too old for CSS relative colours keeps the theme's own values for those.)

The brand colour sits in a small file of its own, tune.css, beside two more values: the corner base, which every corner is a step of, and the density base, which every padding, gap and control height is a step of. It holds the theme's own values. Your agent never edits it, and never writes a colour into a part.

The stylesheets, in order

Your app's main stylesheet imports Tailwind, then the theme's stylesheets, with tune.css last so its values win. Your agent sets this up when it installs the first part.

Show the exact imports

Trail's, for example; every theme's follow the same order from its own folder:

CSS
@import "tailwindcss";
@import "./goop/contract.css";
@import "./goop/base.css";
@import "./goop/trail/theme.css";
@import "./goop/trail/extensions.css";
@import "./goop/trail/base.css";
@import "./goop/trail/tune.css";
  • contract.css gives Tailwind's names to the theme's variables (bg-primary is var(--primary)).
  • goop/base.css is the base every part assumes: borders in the theme's border colour, the body in its background, text and typeface.
  • theme.css holds the values: light on :root, dark under .dark.
  • extensions.css maps the theme's own tokens beyond the shared set; its base.css (goop/trail/base.css in Trail) loads its typefaces.
  • tune.css holds the brand colour, the corner base and the density base, imported last.

Trail's stylesheet guide has the rest, with the two stylesheets you import only for a choice of your own.

Where would you like to start?

Free · now

The Goop plugin

A design system for your AI coding agent, so screen ten matches screen one.

/plugin marketplace add goop-so/skillsthen /plugin install goop@goopCodex, Cursor, ChatGPT, the Claude app and more: Connect Goop
FreePro

The components

Every part live, with its props, its keys and what an agent sees. Whole page and app templates, working with sample data.