Colore JS

Search documentation

Find a function or jump to a section.
v2.0.1

adjustCssVariables

adjustCssVariables changes how a theme feels without rebuilding it. Pick the tokens (surfaces, borders, the brand), pick a mode, and move their lightness, chroma or hue in OKLCH. Every other value in the file stays exactly as it was.

Example

Warm and lift the dark-mode surfaces:

import { adjustCssVariables } from 'colore-js';

const css = `:root {
  --surface: oklch(0.94 0 0);
  --brand: #0f766e;
}
.dark {
  --surface: oklch(0.2 0 0);
}`;

const result = adjustCssVariables(css, {
  groups: ['surfaces'],
  modes: ['dark'],
  lightness: '+0.03',
  chroma: 0.015,
  hue: 65,
});

console.log(result.css);
:root {
  --surface: oklch(0.94 0 0);
  --brand: #0f766e;
}
.dark {
  --surface: oklch(0.23 0.015 65);
}

Syntax

adjustCssVariables(css: string, options: AdjustThemeOptions): ThemeEditResult

Options

Choose at least one group or token, and at least one channel.

OptionTypeDescription
groupsThemeGroup[]The token groups to change.
tokensstring[]Token names, with or without --. Combined with groups.
modesThemeMode[]The modes to change. Defaults to ['light', 'dark'].
lightnessChannelChangeOKLCH lightness, kept between 0 and 1.
chromaChannelChangeOKLCH chroma, kept at 0 or above.
hueChannelChangeOKLCH hue in degrees, wrapped around the color wheel.

A ChannelChange is a number to set the channel (0.015), a signed string to add or subtract ('+0.03', '-10'), or 'x' and a factor to scale it ('x0.8'). Grays have no hue, so give them some chroma when you tint them.

Results stay in the gamut the color started in, sRGB or Display P3.

Returns

A ThemeEditResult with the updated css and the list of changes, the same shape as applyThemeToCss.

Token groups

GroupTypical tokens
surfacesbackground, card, popover, muted, secondary, sidebar
textforeground, muted-foreground and every other -foreground
brandprimary, ring, sidebar-primary
accentaccent
bordersborder, input
statusdestructive, success, warning
chartschart-1 to chart-5
otherAnything else

Recipes

RequestOptions
Warmer neutrals{ groups: ['surfaces', 'borders'], hue: 70, chroma: 0.008 }
Calmer accent{ groups: ['accent'], chroma: 'x0.6' }
Darker buttons in light mode{ tokens: ['primary'], modes: ['light'], lightness: '-0.04' }
Softer dark mode{ groups: ['surfaces'], modes: ['dark'], lightness: '+0.03' }

An adjustment can lower contrast. Check the result with auditCssVariables and repair it with fixCssVariables, or use colore adjust from the CLI, which repairs and audits for you.