Skip to content
Glazev3.3.0
Color scheme
Contrast
Color scheme
Contrast

Accessible color systems from one seed.

Describe each color as a tone step from another, with a WCAG or APCA contrast floor. Glaze solves light, dark, and high-contrast themes to those floors, and warns when one is out of reach.
Try it: hue, saturation, and contrast level
View source
<!doctype html><meta charset="utf-8"><style>:root {
  color-scheme: light dark;
  --page: rgb(255 255 255); --card: rgb(244.02 244.31 246.42); --border: rgb(203.3 204.91 217.08); --text: rgb(29.4 30.88 51.78); --text-soft: rgb(106.44 109.66 140.41); --link: rgb(99.3 94.64 222.22); --accent: rgb(105.08 102.1 227.43); --accent-label: rgb(255 255 255); --shadow: rgb(0 0 0 / 0.1088);
}
@media (prefers-color-scheme: dark) {
  :root { --page: rgb(33.57 34.08 37.99); --card: rgb(39.24 40.06 46.72); --border: rgb(59.82 61.26 73.54); --text: rgb(226.62 228.26 240.65); --text-soft: rgb(138.39 141.61 169.6); --link: rgb(130.13 134.03 230.41); --accent: rgb(97.26 95.72 206.43); --accent-label: rgb(238.15 239.84 252.54); --shadow: rgb(0 0 0 / 0.8015); }
}
html { background: var(--page); color: var(--text); }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif; }
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.field {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 8px;
}
.field label { font-weight: 600; }
.field output { color: var(--text-soft); font-variant-numeric: tabular-nums; }
.field input, .field small { grid-column: 1 / -1; }
.field small { font-size: 12px; color: var(--text-soft); }
input[type='range'] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
}
input[type='checkbox'] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}
.segmented {
  display: flex;
  margin: 0;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.segmented label {
  flex: 1;
  padding: 6px 12px;
  border-radius: 6px;
  text-align: center;
  white-space: nowrap;
  cursor: pointer;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(:checked) { background: var(--accent); color: var(--accent-label); }
@media (forced-colors: active) {
  .segmented label:has(:checked) {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
  }
}
.segmented label:has(:focus-visible),
button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}
button {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
code, pre {
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
}
code {
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--card);
}
.demo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 17rem;
  align-items: start;
  gap: 24px 32px;
  padding: 24px;
}
@media (max-width: 40rem) {
  .demo { grid-template-columns: minmax(0, 1fr); gap: 20px; padding: 16px; }
}
.result { display: grid; gap: 16px; }
.card {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 12px 28px -4px var(--shadow);
}
.small { font-size: 13px; }
.soft { color: var(--text-soft); }
.title { font-size: 18px; font-weight: 600; line-height: 1.3; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 8px; }
.button {
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-label);
  font-size: 13px;
  font-weight: 600;
}
.link { color: var(--link); font-weight: 600; text-decoration: underline; }
.readouts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}
.readouts dt { font-size: 13px; color: var(--text-soft); }
.readouts dd { display: grid; margin: 0; }
.readouts output {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.readouts small { font-size: 12px; color: var(--text-soft); }
.controls { display: grid; gap: 16px; }
.actions { display: flex; align-items: center; gap: 8px; }
.actions .segmented { flex: 1; }</style><div class="demo">
  <div class="result">
    <div class="card">
      <span class="small soft">Quarterly report</span>
      <span class="title">Revenue is up 12%</span>
      <span class="soft">Every color on this card is solved from the seed and the contrast level you set.</span>
      <span class="row">
        <span class="button">Publish</span>
        <span class="small link">View details</span>
      </span>
    </div>
    <dl class="readouts" hidden>
      <div><dt>Body text</dt><dd><output id="body-ratio" aria-live="off"></output><small id="body-floor"></small></dd></div>
      <div><dt>Link</dt><dd><output id="link-ratio" aria-live="off"></output><small id="link-floor"></small></dd></div>
      <div><dt>Button</dt><dd><output id="button-ratio" aria-live="off"></output><small id="button-floor"></small></dd></div>
    </dl>
    <code id="call" hidden></code>
  </div>
  <div class="controls" role="group" aria-label="Theme" hidden>
    <div class="field">
      <label for="hue">Hue</label>
      <output for="hue" id="hue-value" aria-live="off">280°</output>
      <input type="range" id="hue" min="0" max="359" value="280">
    </div>
    <div class="field">
      <label for="saturation">Saturation</label>
      <output for="saturation" id="saturation-value" aria-live="off">80</output>
      <input type="range" id="saturation" min="0" max="100" value="80">
    </div>
    <div class="field">
      <label for="level">Contrast level</label>
      <output for="level" id="level-value" aria-live="off">0</output>
      <input type="range" id="level" min="0" max="100" value="0" aria-describedby="level-hint">
      <small id="level-hint">0 is the palette as authored; 100 is its high-contrast tier.</small>
    </div>
    <div class="actions">
      <fieldset class="segmented">
        <legend class="visually-hidden">Scheme</legend>
        <label><input type="radio" name="scheme" value="light">Light</label>
        <label><input type="radio" name="scheme" value="dark">Dark</label>
      </fieldset>
      <button type="button" id="reset">Reset</button>
    </div>
  </div>
  <p class="visually-hidden" aria-live="polite" id="announce"></p>
</div><script src="/demo/glaze.iife.js"></script><script>// The card's color definitions (UI_COLORS), and which color paints each part.
const COLORS = {"surface":{"tone":100,"saturation":0.1},"card":{"base":"surface","tone":"-3","saturation":0.15},"text":{"base":"card","tone":4,"saturation":0.45},"text-soft":{"base":"card","tone":"-1","saturation":0.3,"contrast":"AA"},"border":{"base":"card","tone":["-12","-24"],"saturation":0.2},"link":{"base":"card","tone":"-1","contrast":"AA"},"accent-label":{"tone":100,"mode":"fixed"},"accent":{"base":"accent-label","tone":"-1","contrast":"AA","mode":"fixed"},"card-shadow":{"type":"shadow","bg":"surface","fg":"card","intensity":8}};
const PARTS = {"page":"surface","card":"card","border":"border","text":"text","text-soft":"text-soft","link":"link","accent":"accent","accent-label":"accent-label","shadow":"card-shadow"};
// Each readout: the text and its background, and the contrast floor the
// solved one of the two carries.
const READOUTS = {"body":{"fg":"text-soft","bg":"card","contrast":"AA"},"link":{"fg":"link","bg":"card","contrast":"AA"},"button":{"fg":"accent-label","bg":"accent","contrast":"AA"}};
const DEFAULTS = {
  hue: 280,
  saturation: 80,
  // Start at the high-contrast tier when the system asks for more contrast.
  level: matchMedia('(prefers-contrast: more)').matches ? 100 : 0,
};

const {
  glaze,
  variantToOkhsl,
  okhslToLinearSrgb,
  gamutClampedLuminance,
  contrastRatioFromLuminance,
  resolveContrastForLevel,
} = Glaze;

const $ = (id) => document.getElementById(id);
const root = document.documentElement;
const inputs = { hue: $('hue'), saturation: $('saturation'), level: $('level') };
const radios = [...document.querySelectorAll('input[name="scheme"]')];
const darkQuery = matchMedia('(prefers-color-scheme: dark)');
// 'light' or 'dark' once the reader picks one; until then, follow the page.
let pinned = null;
let solved;

const scheme = () => pinned ?? (darkQuery.matches ? 'dark' : 'light');
const seed = () => ({
  hue: +inputs.hue.value,
  saturation: +inputs.saturation.value,
  level: +inputs.level.value,
});

function luminance(v) {
  const { h, s, l } = variantToOkhsl(v);
  return gamutClampedLuminance(okhslToLinearSrgb(h, s, l, v.pastel ?? false));
}

function solve() {
  const { hue, saturation, level } = seed();
  const theme = glaze(hue, saturation, level ? { contrastLevel: level } : undefined);
  theme.colors(COLORS);
  solved = {
    css: theme.json({ format: 'rgb', modes: { dark: true, highContrast: false } }),
    variants: theme.resolve(),
  };
  $('hue-value').textContent = hue + '°';
  $('saturation-value').textContent = saturation;
  $('level-value').textContent = level;
  inputs.hue.setAttribute('aria-valuetext', hue + ' degrees');
  inputs.level.setAttribute('aria-valuetext', level + ' of 100');
  $('call').textContent =
    'glaze(' + hue + ', ' + saturation + (level ? ', { contrastLevel: ' + level + ' }' : '') + ')';
  paint();
}

function paint() {
  const s = scheme();
  for (const [part, name] of Object.entries(PARTS)) {
    root.style.setProperty('--' + part, solved.css[name][s]);
  }
  root.style.colorScheme = s;
  for (const radio of radios) radio.checked = radio.value === s;

  const { level } = seed();
  for (const [id, { fg, bg, contrast }] of Object.entries(READOUTS)) {
    const ratio = contrastRatioFromLuminance(
      luminance(solved.variants.get(fg)[s]),
      luminance(solved.variants.get(bg)[s]),
    );
    const floor = resolveContrastForLevel(contrast, level).target;
    const tier = floor === 4.5 ? 'AA ' : floor === 7 ? 'AAA ' : '';
    $(id + '-ratio').textContent = ratio.toFixed(2) + ':1';
    $(id + '-floor').textContent = tier + 'floor ' + floor.toFixed(2);
  }
}

function announce() {
  const read = (id) => $(id + '-ratio').textContent.replace(':1', ' to 1');
  $('announce').textContent =
    'Body text ' + read('body') + ', link ' + read('link') + ', button ' + read('button') + '.';
}

for (const input of Object.values(inputs)) {
  input.addEventListener('input', solve);
  input.addEventListener('change', announce);
}
for (const radio of radios) {
  radio.addEventListener('change', () => {
    pinned = radio.value;
    paint();
    announce();
  });
}
darkQuery.addEventListener('change', () => {
  if (!pinned) paint();
});
$('reset').addEventListener('click', () => {
  inputs.hue.value = DEFAULTS.hue;
  inputs.saturation.value = DEFAULTS.saturation;
  inputs.level.value = DEFAULTS.level;
  pinned = null;
  solve();
  announce();
});

inputs.level.value = DEFAULTS.level;
solve();
for (const hidden of document.querySelectorAll('[hidden]')) hidden.hidden = false;</script>

Every color on this card — page, card, border, text, link, button, and shadow — comes from one Glaze theme of nine color definitions, solved in your browser as you move the sliders. Hue and saturation recolor the card, but the body text, link, and button never drop below their WCAG AA floor of 4.5:1. The contrast level raises the floors toward the theme’s high-contrast tier, which it reaches at 100.

Four schemes from one definition

Light, dark, light high-contrast, and dark high-contrast variants share one model. Dark mode inverts tone (100 − t) and fits it into a dark tone window, so the relationships between colors survive the switch — there is no second palette to maintain. High-contrast variants use the full tone range and the raised contrast floors.

Light
Quarterly reportRevenue is up 12%Every color on this card was resolved by Glaze for the scheme you are viewing.
PublishView details
Dark
Quarterly reportRevenue is up 12%Every color on this card was resolved by Glaze for the scheme you are viewing.
PublishView details
Light · high contrast
Quarterly reportRevenue is up 12%Every color on this card was resolved by Glaze for the scheme you are viewing.
PublishView details
Dark · high contrast
Quarterly reportRevenue is up 12%Every color on this card was resolved by Glaze for the scheme you are viewing.
PublishView details
The card from the top of this page at its starting seed (hue 280, saturation 80), in each scheme on its own background.

Color relationships, not color tables

Glaze turns a hue and saturation seed into a complete palette. Instead of picking every color, you say how each color relates to the others. A root color places itself with an absolute tone. A dependent color names a base and sits a signed tone delta away from it, optionally with a contrast floor. Glaze resolves the actual colors for every scheme. Here are four of the card’s nine colors:

theme.ts

ts

import { glaze } from '@tenphi/glaze';

const theme = glaze(280, 80);

theme.colors({
  surface: { tone: 100, saturation: 0.1 },
  card: { base: 'surface', tone: '-3', saturation: 0.15 },
  border: {
    base: 'card',
    tone: ['-12', '-24'],
    saturation: 0.2,
  },
  'text-soft': {
    base: 'card',
    tone: '-1',
    saturation: 0.3,
    contrast: 'AA',
  },
});
surfacetone 100.0tone 9.3tone 100.0tone 0.0
cardtone 97.0tone 11.9tone 97.0tone 3.0
bordertone 85.0tone 22.2tone 73.0tone 27.0
text-softtone 47.6tone 61.8tone 33.0tone 67.4

In dark mode the tone scale inverts, so card and border step lighter instead of darker, in the same order. The dark tone window scales the steps down a little (about 2.6 and 10.4 tones here). The high-contrast variants keep the exact 3, and border takes the second value of its pair, 24. See how relative tone adapts.

Contrast-aware by construction

Set a WCAG ratio or an APCA Lc floor on the colors that need one. Glaze keeps the tone you asked for when it already clears the floor with a small margin, otherwise moves it about as far as the floor requires, and warns when a floor can’t be met, on a color or a mix. Each tile below measures the resolved colors in the scheme you’re viewing.

surface-text-soft4.55:14.55:17.07:17.07:1Text at this contrast reads like this.contrast: 'AA'
surface-text7.07:17.07:17.07:17.07:1Text at this contrast reads like this.contrast: 'AAA'
accent-textLc 75.5Lc 75.5Lc 90.5Lc 90.5Text at this contrast reads like this.contrast: { apca: 'body' }

In high contrast, a floor without an explicit high-contrast value rises a tier: 'AA' becomes 'AAA' and an APCA target gains 15 Lc. A numeric WCAG ratio stays as written.

A tone axis built for contrast

Glaze works in OKHST: OKHSL with lightness replaced by tone, an axis shaped by WCAG luminance. Equal tone steps are equal contrast steps for neutrals and an approximation for chromatic colors, so a delta like '-8' means the same visible distance anywhere on the scale.

0
10
20
30
40
50
60
70
80
90
100
1.361.361.361.361.361.361.361.361.361.36
Tone 0 to 100 in steps of 10, with the WCAG ratio between neighbors: every step is the same.
0
10
20
30
40
50
60
70
80
90
100
1.161.331.431.461.451.421.381.351.321.29
The same steps in OKHSL lightness: the ratio between neighbors drifts from step to step.

Shadows and glows with exact steps

shadow and glow colors are translucent overlays — black for a shadow and white for a glow by default. Glaze solves their opacity per surface, so once the browser composites them the surface lands exactly intensity tones darker or lighter: on light, dark, and chromatic surfaces alike, as long as the surface has room for the step. A shadow can’t go past black and a glow can’t go past white in SDR, so an out-of-reach step gets as close as it can and logs a console warning (see unreachable steps). To see one, set the card at the top of this page to Dark and drag its contrast level to 100: the page turns black and the card shadow disappears. That one stays out of the console: the contrast level moved the page, and light still has room for the shadow. An optional object color (fg) deepens or softens the step the way bounce light does.

tone 97
α 0.108−8.0 tones
tone 70
α 0.120−8.0 tones
tone 50 · chromatic
α 0.144−8.0 tones
tone 30
α 0.201−8.0 tones
A shadow with intensity 8 on four surfaces. The opacity changes with the surface; the step does not.
tone 10
α 0.080+8.0 tones
tone 20
α 0.079+8.0 tones
tone 35 · chromatic
α 0.102+8.0 tones
tone 50
α 0.128+8.0 tones
A glow with intensity 8 on darker surfaces, for elevation and highlights in dark interfaces.

Ready for applications and design tools

Export CSS custom properties, a Tailwind CSS v4 theme, W3C DTCG design tokens (one file per scheme, or a single Resolver-Module document), plain JSON, or Tasty bindings. Every tab below is the real output of the theme in the first tab.

theme.ts

ts

import { glaze } from '@tenphi/glaze';

const theme = glaze(280, 80);

theme.colors({
  surface: { tone: 97, saturation: 0.15 },
  'surface-text': {
    base: 'surface',
    tone: '-1',
    saturation: 0.4,
    contrast: 'AAA',
  },
});

theme.css(); // CSS custom properties
theme.tailwind(); // Tailwind CSS v4 theme
theme.tasty(); // Tasty tokens
theme.dtcg(); // W3C design tokens, one tree per scheme
theme.json(); // plain JSON

CSS

css

:root {
  --surface-color: oklch(0.97 0.0027 280);
  --surface-text-color: oklch(0.4445 0.059 280);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-color: oklch(0.279 0.0122 280);
    --surface-text-color: oklch(0.7717 0.0422 280);
  }
}

Tailwind

css

@theme {
  --color-surface: oklch(0.97 0.0027 280);
  --color-surface-text: oklch(0.4445 0.059 280);
}

.dark {
  --color-surface: oklch(0.279 0.0122 280);
  --color-surface-text: oklch(0.7717 0.0422 280);
}

Tasty

json

{
  "#surface": {
    "": "oklch(0.97 0.0027 280)",
    "@media(prefers-color-scheme: dark)": "oklch(0.279 0.0122 280)"
  },
  "#surface-text": {
    "": "oklch(0.4445 0.059 280)",
    "@media(prefers-color-scheme: dark)": "oklch(0.7717 0.0422 280)"
  }
}

DTCG

json

{
  "light": {
    "surface": {
      "$type": "color",
      "$value": {
        "colorSpace": "srgb",
        "components": [
          0.959046,
          0.960132,
          0.967978
        ],
        "hex": "#f5f5f7"
      }
    },
    "surface-text": {
      "$type": "color",
      "$value": {
        "colorSpace": "srgb",
        "components": [
          0.30253,
          0.314369,
          0.455264
        ],
        "hex": "#4d5074"
      }
    }
  },
  "dark": {
    "surface": {
      "$type": "color",
      "$value": {
        "colorSpace": "srgb",
        "components": [
          0.153894,
          0.157112,
          0.183216
        ],
        "hex": "#27282f"
      }
    },
    "surface-text": {
      "$type": "color",
      "$value": {
        "colorSpace": "srgb",
        "components": [
          0.685713,
          0.699508,
          0.81548
        ],
        "hex": "#afb2d0"
      }
    }
  }
}

JSON

json

{
  "surface": {
    "light": "oklch(0.97 0.0027 280)",
    "dark": "oklch(0.279 0.0122 280)"
  },
  "surface-text": {
    "light": "oklch(0.4445 0.059 280)",
    "dark": "oklch(0.7717 0.0422 280)"
  }
}

Glaze has zero runtime dependencies, is written in TypeScript with full type definitions, ships tree-shakeable ESM and CommonJS builds, and runs in Node.js, browsers, and edge runtimes.

More in the box

  • Manual contrast level. Put the normal palette on a 0–100 slider toward high contrast. Every level in between is solved, not approximated, and the high-contrast tier stays available on top. It’s the Contrast level slider on the card at the top of this page. See manual contrast level.
  • Dark seed and per-color hue. Give dark schemes their own hue and saturation seed, or shift one color’s hue absolutely or relative to the seed. See dark seed and hue and saturation.
  • Mixes. Blend two colors in OKHSL or sRGB, opaque or transparent, with optional contrast solving. See Mixes and transparency.
  • HDR glows. Set glowTuning.headroom, and a glow whose step passes white also gets an exact HDR value for native apps and WebGPU canvases on HDR displays; exporters add it when you turn on modes.hdr. See HDR glows.
  • Brand colors. Start a theme from a hex or RGB value with glaze.fromHex() / glaze.fromRgb(), or seed a single color from a literal value with from. See fromHex / fromRgb and from.
  • Standalone colors. glaze.color() gives one color, or a pair with a contrast floor, the same scheme adaptation without a theme. See Color tokens.
  • Palettes. Derive status themes with extend() and compose them into one prefixed token set with glaze.palette(). See Designing a palette and Palettes.
  • Snapshots. Export themes, color tokens, and palettes as JSON and restore them with glaze.themeFrom(), glaze.colorFrom(), and glaze.paletteFrom(). See Exporting and integration.
  • Output formats. Native oklch(), rgb(), and hsl(), plus Tasty’s okhsl() and okhst(). See color formats.

Quick start

pnpm

shell

pnpm add @tenphi/glaze

npm

shell

npm install @tenphi/glaze

yarn

shell

yarn add @tenphi/glaze
import { glaze } from '@tenphi/glaze';

glaze.configure({
  modes: { dark: true, highContrast: true },
});

const theme = glaze(280, 80);

theme.colors({
  surface: { tone: 97, saturation: 0.15 },
  'surface-text': {
    base: 'surface',
    tone: '-1',
    saturation: 0.4,
    contrast: { apca: ['content', 'body'] },
  },
  border: {
    base: 'surface',
    tone: ['-8', '-16'],
    saturation: 0.2,
    inherit: false,
  },
  'accent-surface-text': { tone: 100, mode: 'fixed' },
  'accent-surface': {
    base: 'accent-surface-text',
    tone: '-1',
    contrast: 'AA',
    mode: 'fixed',
  },
});

const danger = theme.extend({ hue: 23 });
const palette = glaze.palette({ default: theme, danger });

const tokens = palette.tokens({
  prefix: { default: '', danger: 'danger-' },
});
// → {
//   light: { surface: 'oklch(...)', 'danger-surface': 'oklch(...)', ... },
//   dark: { ... },
//   lightContrast: { ... },
//   darkContrast: { ... },
// }

border is marked inherit: false, so the danger theme gets every color except it.

Where to go next

Explore the tone axis in the ramp explorer, read the full OKHST specification for the math behind it, or see AGENTS.md for a tour of the source tree.