Create a Theme

term.css themes override 10 CSS custom properties. You can create a theme manually or use the CLI generator.

Theme File Structure

A theme file overrides variables in a single :root block using light-dark() for both modes:

/* my-theme.css */
:root {
color-scheme: light dark;
--t-bg: light-dark(oklch(0.97 0.01 200), oklch(0.15 0.02 200));
--t-fg: light-dark(oklch(0.20 0.02 200), oklch(0.85 0.02 200));
--t-muted: light-dark(oklch(0.45 0.02 200), oklch(0.58 0.02 200));
--t-accent: light-dark(oklch(0.45 0.15 200), oklch(0.75 0.15 200));
--t-accent2: light-dark(oklch(0.50 0.15 200), oklch(0.65 0.15 200));
--t-surface: light-dark(oklch(0.93 0.01 200), oklch(0.20 0.02 200));
--t-border: light-dark(oklch(0.80 0.01 200), oklch(0.30 0.02 200));
--t-red: light-dark(oklch(0.55 0.20 25), oklch(0.65 0.20 25));
--t-yellow: light-dark(oklch(0.55 0.16 85), oklch(0.78 0.16 85));
--t-green: light-dark(oklch(0.50 0.17 145), oklch(0.72 0.19 145));
}
/* Manual overrides */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

Variable Reference

VariablePurposeDark L rangeLight L range
--t-bgPage background0.12-0.200.95-0.98
--t-fgBody text0.82-0.900.15-0.25
--t-mutedSecondary text0.55-0.620.40-0.50
--t-accentLinks, headings0.70-0.800.40-0.50
--t-accent2Badges, marks0.60-0.700.45-0.55
--t-surfaceCode, cards0.18-0.250.90-0.95
--t-borderBorders0.28-0.350.75-0.85
--t-redError, danger0.53-0.600.50-0.58
--t-yellowWarning, caution0.70-0.800.50-0.58
--t-greenSuccess, confirmed0.65-0.750.45-0.55

Contrast Requirements

Important

All themes must meet WCAG 2.1 AA contrast ratios.

PairMinimum RatioStandard
fg / bg4.5:1AA normal text
muted / bg4.5:1AA normal text
accent / bg4.5:1AA normal text
red / bg4.5:1AA normal text
yellow / bg4.5:1AA normal text
green / bg4.5:1AA normal text

The CLI generator validates these automatically and exits with an error if any ratio fails.

CLI Generator

Generate a complete theme from a single hue value:

npx termcss --hue 200 --name ocean

Options:

FLAGS
--hue <0-360> Base hue for the theme (required)
--name <name> Theme name (required)
--chroma <0-0.4> Color intensity (default: 0.15)
--out <path> Output path (default: ./<name>.css)

The generator creates both dark and light mode values with consistent lightness steps, and validates WCAG AA contrast for every color pair.

Example

# Generate an ocean theme
npx termcss --hue 200 --name ocean
# Generate a warm theme with lower chroma
npx termcss --hue 30 --name warm --chroma 0.10
# Output to a custom path
npx termcss --hue 280 --name purple --out ./my-theme.css

OKLCH Color Space

term.css uses OKLCH for all colors. OKLCH is a perceptually uniform color space where:

This makes it possible to generate mathematically correct themes by fixing lightness values and rotating the hue.

Community Themes

To submit a theme:

  1. Create a theme file in src/themes/
  2. Ensure all contrast ratios pass (pnpm check:contrast validates all shipped themes)
  3. Test in both dark and light modes
  4. Submit a PR to the GitHub repo
Tip

Try the interactive playground to experiment with hue and chroma values before generating a theme file.