Tone and OKHST
Glaze places every color in OKHST: OKHSL’s hue and saturation, with the lightness axis replaced by tone — a 0–100 axis shaped so that equal tone steps give equal WCAG contrast. This page is the reference for the color model as Glaze applies it: the transfer math, what tone does and does not guarantee, and how an authored tone becomes a rendered color in each scheme. The OKHST repository is the canonical specification of the color space itself: transfer functions, derivation, and invariants.
To build a palette on this model, continue to Designing a palette. Every option and utility named here is listed in the API reference.
OKHST keeps OKHSL’s hue (h, 0–360) and saturation (s) verbatim and swaps
the third coordinate:
| Space | Coordinates | Third coordinate |
|---|---|---|
| OKHSL | h, s, l |
l: perceptual lightness (toe-adjusted OKLab L) |
| OKHST | h, s, t |
t: tone, a normalized logarithm of luminance |
You author tone on a 0–100 scale (tone: 97). Resolved variants and the
{ h, s, t } input object carry it on 0–1, like saturation (hue stays 0–360).
OKHSL lightness is perceptually even, but equal lightness steps produce uneven
contrast: the ratio between neighbors changes along the axis. Tone is shaped so
equal steps produce equal WCAG contrast. Two things follow: a ramp authored in
tone is a contrast-even ladder for free, and dark-mode inversion is a single
subtraction (100 - t) instead of a fitted curve.
Build a ramp for any hue and saturation, spaced in tone or in OKHSL lightness.
A gray tone ramp keeps the same ratio between every pair of neighbors. A
saturated one stays close: hue 280 at saturation 80 runs from 1.32:1 to 1.38:1
in tone, against 1.14:1 to 1.46:1 in lightness (see
chromatic drift). Open Values to copy
each step as hex and oklch().
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; gap: 20px; padding: 20px; }
.controls {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px 24px;
}
.options {
grid-column: 1 / -1;
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px 20px;
}
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
@media (max-width: 36rem) {
.demo { padding: 16px; }
.controls { grid-template-columns: minmax(0, 1fr); }
}
.result { display: grid; gap: 8px; }
.ramp, .ratios {
display: grid;
grid-auto-flow: column;
grid-auto-columns: minmax(0, 1fr);
}
.ramp {
overflow: hidden;
/* The steps touch, so every edge shows its contrast step; the frame keeps
the black and white ends visible on a page of the same color. */
border: 1px solid var(--border);
border-radius: 6px;
}
.step {
display: grid;
align-content: end;
min-height: 64px;
padding: 4px;
color: var(--ink);
font: 600 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
}
/* A label may run onto the unlabelled steps after it, above their fill. */
.step span { position: relative; white-space: nowrap; }
.ratios {
color: var(--text-soft);
font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: center;
}
.ratios span { grid-column: span 2; white-space: nowrap; }
.ratios span.offset { grid-column: span 1; }
.step.quiet { color: transparent; }
.summary { margin: 4px 0 0; }
summary { width: fit-content; color: var(--text-soft); cursor: pointer; }
pre {
overflow-x: auto;
margin: 8px 0 0;
padding: 10px 12px;
border-radius: 6px;
background: var(--card);
user-select: all;
}</style><div class="demo">
<div class="controls" role="group" aria-label="Ramp" 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="steps">Steps</label>
<output for="steps" id="steps-value" aria-live="off">11</output>
<input type="range" id="steps" min="3" max="21" value="11">
</div>
<div class="options">
<fieldset class="segmented">
<legend class="visually-hidden">Spacing</legend>
<label><input type="radio" name="axis" value="tone" checked>Tone</label>
<label><input type="radio" name="axis" value="lightness">OKHSL lightness</label>
</fieldset>
<label class="check"><input type="checkbox" id="pastel">Pastel</label>
</div>
</div>
<div class="result" hidden>
<div class="ramp" id="ramp" aria-hidden="true"></div>
<div class="ratios" id="ratios" aria-hidden="true"></div>
<p class="summary" id="summary"></p>
<details>
<summary>Values</summary>
<pre id="values"></pre>
</details>
</div>
<p class="visually-hidden" aria-live="polite" id="announce"></p>
</div><script src="/demo/glaze.iife.js"></script><script>const {
fromTone,
okhslToLinearSrgb,
okhslToSrgb,
gamutClampedLuminance,
contrastRatioFromLuminance,
formatOklch,
} = Glaze;
// Black or white ink, whichever has more contrast on the step: they tie at
// the luminance where (Y + 0.05) / 0.05 = 1.05 / (Y + 0.05).
const INK_CROSSOVER_Y = Math.sqrt(1.05 * 0.05) - 0.05;
const INK = { dark: 'rgb(0 0 0 / 0.86)', light: 'rgb(255 255 255 / 0.94)' };
// A step label or a neighbor ratio needs about this many pixels. Narrower
// steps label every other step (or fewer) and leave the ratios to the summary.
const MIN_CELL = 36;
const $ = (id) => document.getElementById(id);
const inputs = { hue: $('hue'), saturation: $('saturation'), steps: $('steps') };
const pastel = $('pastel');
const axes = [...document.querySelectorAll('input[name="axis"]')];
const ratio = (a, b) => contrastRatioFromLuminance(a, b).toFixed(2);
const label = (value) => String(+value.toFixed(1));
const hex = (rgb) =>
'#' + rgb.map((c) => Math.round(c * 255).toString(16).padStart(2, '0')).join('');
function render() {
const hue = +inputs.hue.value;
const saturation = +inputs.saturation.value;
const steps = +inputs.steps.value;
const axis = axes.find((a) => a.checked).value;
const s = saturation / 100;
const p = pastel.checked;
const cells = Array.from({ length: steps }, (_, i) => {
const value = (i * 100) / (steps - 1);
const l = axis === 'tone' ? fromTone(value) : value / 100;
const y = gamutClampedLuminance(okhslToLinearSrgb(hue, s, l, p));
return { value, l, y };
});
$('ramp').replaceChildren(
...cells.map((cell) => {
const step = document.createElement('span');
step.className = 'step';
step.append(Object.assign(document.createElement('span'), { textContent: label(cell.value) }));
step.style.background = hex(okhslToSrgb(hue, s, cell.l, p));
step.style.setProperty('--ink', cell.y > INK_CROSSOVER_Y ? INK.dark : INK.light);
return step;
}),
);
const ratios = cells.slice(1).map((cell, i) => ratio(cells[i].y, cell.y));
const offset = () => Object.assign(document.createElement('span'), { className: 'offset' });
$('ratios').replaceChildren(
offset(),
...ratios.map((r) => Object.assign(document.createElement('span'), { textContent: r })),
offset(),
);
const low = Math.min(...ratios);
const high = Math.max(...ratios);
const spacing = axis === 'tone' ? 'tone' : 'OKHSL lightness';
$('summary').textContent =
low.toFixed(2) === high.toFixed(2)
? 'Evenly spaced in ' + spacing + ': ' + low.toFixed(2) + ':1 between every pair of neighbors.'
: 'Evenly spaced in ' + spacing + ': ' + low.toFixed(2) + ':1 to ' + high.toFixed(2) + ':1 between neighbors.';
$('values').textContent = cells
.map((cell) => {
const name =
axis === 'tone' ? 'tone ' + label(cell.value) : 'l ' + label(cell.value) + '%';
return name.padEnd(10) + hex(okhslToSrgb(hue, s, cell.l, p)) + ' ' + formatOklch(hue, s, cell.l, p);
})
.join('\n');
$('hue-value').textContent = hue + '°';
$('saturation-value').textContent = saturation;
$('steps-value').textContent = steps;
inputs.hue.setAttribute('aria-valuetext', hue + ' degrees');
fit();
}
function fit() {
const ramp = $('ramp');
const width = ramp.clientWidth / ramp.children.length;
if (!width) return;
const every = Math.ceil(MIN_CELL / width);
[...ramp.children].forEach((step, i) => step.classList.toggle('quiet', i % every !== 0));
$('ratios').hidden = width < MIN_CELL;
}
for (const input of [...Object.values(inputs), pastel, ...axes]) {
input.addEventListener('input', render);
// Read the summary out once a change settles, not on every step of a drag.
input.addEventListener('change', () => {
$('announce').textContent = $('summary').textContent;
});
}
render();
for (const hidden of document.querySelectorAll('.controls, .result')) hidden.hidden = false;
new ResizeObserver(fit).observe($('ramp'));</script>For a gray (s = 0) at OKHSL lightness l, luminance has a closed form through
the OKHSL toe and the OKLab cube:
Y = toeInv(l)^3 // OKLab L = toeInv(l), cubed
l = toe(cbrt(Y)) // exact inverseTone is a normalized natural logarithm of Y, offset by a small eps:
D = ln(1 + eps) - ln(eps)
toneFromY(Y, eps) = 100 * (ln(Y + eps) - ln(eps)) / D
yFromTone(T, eps) = exp(T / 100 * D + ln(eps)) - epstoTone(l) and fromTone(t) compose these with the gray luminance above, so
they convert between OKHSL lightness (0–1) and tone (0–100) directly. The two
directions are exact analytic inverses: a round trip is lossless to
floating-point precision. toneFromY(0) is 0 and toneFromY(1) is 100 for any
eps, so tone is always a clean 0–100 scale.
WCAG 2 contrast is (Y_hi + 0.05) / (Y_lo + 0.05). With eps = 0.05, tone is a
normalized ln(Y + 0.05), so a fixed tone difference is a fixed ratio of
Y + 0.05 — a fixed WCAG contrast — wherever it sits on the scale. Since
ln(1.05) - ln(0.05) = ln(21):
ratio(T2, T1) = (Y2 + 0.05) / (Y1 + 0.05)
= exp((T2 - T1) / 100 * ln(21))
= 21 ^ ((T2 - T1) / 100)The whole scale is 21:1, black to white, and every 10 tones multiply contrast by
21 ^ 0.1, about 1.36. For neutrals:
| Tone | Contrast vs. black |
|---|---|
| 10 | 1.36:1 |
| 20 | 1.84:1 |
| 30 | 2.49:1 |
| 40 | 3.38:1 |
| 50 | 4.58:1 |
| 60 | 6.21:1 |
| 70 | 8.42:1 |
| 80 | 11.42:1 |
| 90 | 15.49:1 |
| 100 | 21:1 |
Inverted, the tone distance between two neutrals for a target ratio R is
100 * ln(R) / ln(21):
| Ratio | Tone distance |
|---|---|
3:1 ('AA-large') |
36.08 |
4.5:1 ('AA') |
49.40 |
7:1 ('AAA') |
63.92 |
These distances are exact for neutrals only; Same tone, same lightness explains why.
The transfer has no ceiling: toneFromY keeps counting past SDR white
(Y = 1), so tone runs on past 100.
Luminance Y |
Stops above white | Tone |
|---|---|---|
| 1 | 0 | 100 |
| 2 | 1 | 121.98 |
| 4 | 2 | 144.34 |
Each stop, a doubling of Y, adds about 22 tones. The scale is still a
logarithm of Y + 0.05, so equal tone steps past 100 are still equal ratios of
Y + 0.05: 12 tones past white (Y 1.4631, tone 112) is the same ratio as a
12-tone step anywhere else. Contrast does not carry over. WCAG and APCA are
defined only up to SDR white, so a tone past 100 has no contrast meaning, and
the contrast solver never searches there.
Only HDR glows go past 100, in an HDR value kept next to the SDR
one; a resolved variant’s own t stays within 0–1.
okhstToOkhsl({ h, s, t }) passes h and s through unchanged and sets
l = fromTone(100 * t). fromTone depends on the tone (and eps) alone, and OKHSL’s
l → L map has no hue or saturation term: h and s enter only the chroma
math. That gives OKHST its core invariant:
A given tone yields the same OKHSL lightness for every hue and saturation.
OKHST inherits OKHSL’s gamut and reversibility exactly: every (h, s, t) is
realizable and round-trips.
The invariant is about lightness. Equal tone gives equal WCAG and APCA contrast
only for grays: a saturated red and a saturated green at the same tone share an
OKHSL lightness but differ in real luminance Y, because hue, saturation, and
gamut mapping all change the final sRGB values. This chromatic drift is the
one approximation in the model.
At full saturation, the rows above read up to 5.6 tones darker than their tone (hue 300, purple) and 4.1 darker (hue 25, red), up to 2.7 tones lighter (hue 150, green), and within a tone for yellow (hue 110). Across all hues the extremes are 5.6 tones darker, near hue 300, and 2.9 lighter, near hue 143. Drift shrinks with saturation: hue 25 at tone 50 reads 3.9 tones dark at full saturation and 1.6 at half.
That splits the work between two tools:
- Use tone deltas for visual spacing within ramps and between related UI colors. The spacing stays even and ordered for every hue.
- Use
contrastwhen a rendered color must meet a measured WCAG or APCA floor. The solver is the one deliberate exception to the invariant: it moves a color’s tone per hue and saturation until the measured floor is met. See Contrast floors.
Each scheme renders authored tone into a tone window, configured by
lightTone and darkTone:
import { glaze } from '@tenphi/glaze';
glaze.configure({
lightTone: [10, 100],
darkTone: [15, 95],
});The window’s lo and hi are OKHSL-lightness boundaries (0–100). Glaze
converts them to tone, positions the authored tone linearly in that tone
interval, converts the result back to lightness with the window’s eps, and
stores it as canonical tone:
loT = toTone(lo / 100, eps)
hiT = toTone(hi / 100, eps)
l = fromTone(loT + (T / 100) * (hiT - loT), eps)
t = toTone(l) / 100 // canonical tone (0–1), REF_EPSA window takes three forms:
| Form | Meaning |
|---|---|
[lo, hi] |
Boundaries at the reference eps. The common form. |
{ lo, hi, eps } |
Boundaries plus a render curvature for this scheme. Advanced. |
false |
The full range [0, 100] at the reference eps: no boundaries, same tone curve. |
Endpoints clamp to 0–100. A value that is none of the three forms (null
included), a window with lo above hi or a non-finite endpoint, and an eps
outside (0, 1e6] all throw instead of quietly inverting or breaking the
scale. The eps cap is numerical: the transfer divides by
ln(1 + eps) - ln(eps), which loses precision as eps grows and cancels to 0
(NaN tones) from about 1e15, while past about 1e3 the curve is already linear
in luminance. The rules are in
Configuration.
lightTone |
darkTone |
|
|---|---|---|
lo |
10 | 15 |
hi |
100 | 95 |
eps |
0.05 | 0.05 |
| Tone range | 4.95–100 | 9.25–95.9 |
The floors keep mapped tones off pure black in both schemes (OKHSL lightness 10
in light, 15 in dark), and the dark ceiling keeps them short of white at
lightness 95. eps is pinned to the reference 0.05 so the axis stays
WCAG-uniform inside the window. Because the remap is linear in tone, it scales
distances between absolute tones uniformly: about 95% of the authored distance
in light and 86.6% in dark.
High-contrast variants run the same math with the window forced to the full
range [0, 100], keeping the window’s eps. There is no separate high-contrast
curve and no fitted dark curve.
A manual contrast level generalizes that bypass
continuously. With contrastLevel: L and f = L / 100, each boundary moves
toward the full range instead of jumping to it:
lo(f) = lo + (0 - lo) * f
hi(f) = hi + (100 - hi) * fThe light default walks [10, 100] → [0, 100] and the dark default
[15, 95] → [0, 100]; at level 50 they are [5, 100] (tone 1.63–100) and
[7.5, 97.5] (tone 3.15–97.97). The render eps is not interpolated, and a
false window is already the full range, so it is level-invariant.
The continuous form applies to the normal variants only. High-contrast variants are already at the full range, so the level does not widen them further: the bypass is what keeps the high-contrast tier independent of the level. The level itself is covered in Light, dark, and high contrast.
Two eps values play separate roles:
- Reference eps —
REF_EPS = 0.05, fixed. It defines the OKHST color space and Glaze’s canonical tone.okhst()input,{ h, s, t }input, the storedResolvedColorVariant.t, tone deltas, and the contrast solver all use it, which keeps tone comparable between schemes. - Render eps — the
epsof an object tone window. A per-scheme curvature control that only changes how authored tone maps through that scheme’s window. It defaults to the reference value, so by default the two coincide.
When a window’s eps differs from the reference, Glaze maps with it to land a
final OKHSL lightness, then stores toTone(l, REF_EPS), so deltas and contrast
calculations stay on the reference scale. For example,
lightTone: { lo: 10, hi: 100, eps: 0.2 } stores authored tone 50 at 63.89
instead of 52.47: mid tones bend lighter. Most palettes should keep the default.
A regular color’s tone goes through one pipeline per scheme:
authored tone T (0–100)
-> adaptation mode
auto + dark invert: T' = 100 - T
light / fixed keep: T' = T
static identity; skip the window
-> remap into the scheme's tone window (full range for high contrast)
-> render curvature (window eps) -> OKHSL lightness l
-> store canonical tone t = toTone(l, REF_EPS) / 100
// variant { h, s, t, alpha }, t on 0–1
-> at the rendering edge only:
fromTone(100 * t) -> l -> sRGB / luminance
optional: a contrast floor searches tone and overrides tThe first step is the color’s mode. Use auto for surfaces and foregrounds
that should trade places between light and dark, fixed for brand fills and
inverse surfaces that should stay on the same side of the scale, and static
for colors that must not adapt.
Light, dark, and high contrast has the full
table and shows each mode side by side.
Dark tone inversion is not autoFlip. Inversion is ordinary scheme
adaptation, controlled by mode. autoFlip solves a different, local problem:
it may mirror a tone delta that overshoots [0, 100] to the other side of its
base, or let the contrast solver try the opposite side of a base.
Tone is the only channel OKHST adapts across schemes; h and s are authoring
inputs that pass through the tone transfer untouched. The one automatic
adjustment is darkDesaturation, which dark schemes apply to every color except
static ones. A theme, or a single color, can seed a different hue and
saturation for the dark schemes with darkHue / darkSaturation; those pick the
h and s that enter the pipeline and never change how tone is transferred.
An authored dark saturation replaces the darkDesaturation step instead of
stacking with it: a color’s own darkSaturation always does, and the theme’s
seed does for every color that reads it. A from color with no saturation of
its own starts from the literal’s saturation rather than the seed, so it keeps
the step. static colors ignore all of it. The rules are in
Light, dark, and high contrast and
Color definitions.
A color’s tone takes one of three kinds of value. The full syntax, including
[normal, highContrast] pairs, is in
Color definitions.
import { glaze } from '@tenphi/glaze';
const theme = glaze(280, 30);
theme.colors({
surface: { tone: 97 }, // absolute
border: { base: 'surface', tone: '-8' }, // tone delta
deep: { tone: 'min' }, // extreme
ink: { base: 'surface', tone: 'min' }, // extreme anchored to a base
});A number places a color on the 0–100 scale independently of every other color.
Each scheme maps it through the pipeline above, so the stored tone is not the
authored one: surface: { tone: 97 } is stored as 97.15 in light and, inverted
to 3 and mapped into the dark window, as 11.85 in dark. A dependent color (one
with a base) can still take an absolute tone; it is then mapped on its own and
the base only matters to a contrast floor.
A signed string is a tone delta: the signed difference between a dependent color and its base.
border: { base: 'surface', tone: '-8' }How the delta travels depends on the dependent color’s mode:
fixedandstaticin every scheme, andautoin the light schemes: the delta is applied to the base’s resolved tone in that scheme, sign preserved. It is an exact tone step, so for neutrals it is an exact contrast step.autoin the dark schemes: the delta is added to the base’s anchor — where the base sits on the authored scale, the tone its own dark variant is the inversion of — and the result is inverted and mapped through the dark window like an absolute tone. Order and direction carry over — text that sits below its surface in light sits above it in dark.
The anchor depends on how the base got its tone, and the same rules hold in both dark passes:
- An
autobase placed by a tone (a number, afromcolor, an extreme with no base) anchors at its authored tone, and anautotone delta at its base’s anchor plus the delta, so a chain steps evenly. Anautocolor with notoneorcontrastof its own anchors at its base’s anchor. - Any other base, whose dark tone is not the inversion of an authored one — a
fixedorstaticcolor, anautocontrast-solved color, anautoextreme on a base, a mix — anchors at its own dark tone read back through the dark window (the window remap run backwards, then un-inverted), so a dependent follows where the base lands in dark.
On every base, the step is then the dark window’s scale times the delta at the
reference dark eps, 86.6% of the authored delta at the default windows. A
tone-50 base steps '+4' to −3.5 and '-4' to +3.5, and a '-4' hover on an
AAA-solved button steps +3.5 too. A custom dark eps bends the dark window’s
curve, so a dark delta lands where the same authored tone would instead of at a
fixed scale. In dark high contrast the window is the full range, so at the
reference dark eps the step is exact, only mirrored, wherever it fits on the
scale (limits below). The anchor is the authored position, not the base’s light
high-contrast tone, so a custom light eps, which moves that tone (lighter
above the reference 0.05, darker below), doesn’t change the step away from the
ends.
Order carries over only when the base inverts too. An auto delta on a
fixed or static base inverts on its own while the base does not (it keeps
its side, or, as a fixed delta, rides its own base into dark), so it mirrors
to the other side of the base in dark: a '+30' label on a fixed tone-52
fill sits 30 tones above it in light and 26.0 below it in dark. Make such a
dependent fixed as well when it should keep its side.
If base + delta overshoots [0, 100], autoFlip (on by default) mirrors the
delta to the other side of the base; if the mirror overshoots too, or autoFlip
is off, the delta clamps on its authored side. Under auto the flip is decided
on the light tones, and dark mirrors the side light took. Dark then steps on
the authored scale, which adds two limits there:
- A step that fits from the base’s light tone can still run past 0 or 100
from the anchor. In dark it then stops at the dark window’s edge. The light
window lifts authored tone 0 to 4.95, so an
autobase placed by a tone meets this at the bottom:'-4'steps about +1.7 on a tone-2 base and not at all on a tone-0 one. A base anchored at its own dark tone can meet it at either end. Inglaze(280, 40),contrast: 12text on a tone-97 surface sits at 15.6 in light but anchors at 2.7, so a'-4'hover on it steps +2.3 in dark, not +3.5. - An anchor past the dark window — a base a contrast floor or an extreme pushed
beyond its edge, or a
fixeddelta riding its base there — is stepped from where it sits. A step back toward the window moves by the full scaled delta; one further out stops at the window edge or the base, whichever is further out.
High contrast’s windows are the full range, and at the reference light eps
the light one is the identity, so an auto base placed by a tone flips the
same way in both high-contrast schemes and its step fits. The first limit
still applies there under a custom light eps, and to a base anchored at its
own dark tone.
'max' is author tone 100 and 'min' is author tone 0. They select the
corresponding end of the scheme without a magic number.
- Without a base, an extreme flows through the pipeline like any absolute
tone: it lands on the window edge and, under
auto, inverts in dark —'min'is the darkest color in light and the lightest in dark. Usefixedto keep the same end without inverting, orstaticto pin one tone everywhere. - With a base, the dark scheme takes a different path. The windows are
asymmetric, so running the extreme through the dark window would squeeze the
span between it and its base and cost contrast. Instead Glaze measures the
tone shift the light scheme produced between the base and the extreme, then
replays it against the base’s resolved dark tone: mirrored under
auto(both ends invert), same-signed underfixed. Only[0, 100]clamping applies, so the color may render past the dark window’s edge — on purpose, since you asked for the extreme. When the shift does not fit, the color pins at tone 100 or 0.staticcolors are unaffected. High-contrast variants follow the same rule, but their window is already the full range, so the replay matches the plain mapping unless the base itself sits asymmetrically across schemes. With acontrastfloor, an anchored extreme’s starting tone is not clamped back into the scheme window.
const neutral = glaze(0, 0);
neutral.colors({
bg: { tone: 60 },
fg: { base: 'bg', tone: 'max' },
});
// light: bg 62.0, fg 100.0 (shift +38.0, 3.18:1)
// dark: bg 43.9, fg 5.9 (shift -38.0, 3.18:1)A root tone: 'max' in the same theme lands at the dark window’s edge,
tone 9.25, and drops to 2.87:1 against bg in dark.
theme.ts
ts
import { glaze } from '@tenphi/glaze';
const theme = glaze(280, 30);
theme.colors({
surface: { tone: 97 },
border: { base: 'surface', tone: '-8' },
text: { base: 'surface', tone: '-60' },
deep: { tone: 'min' },
ink: { base: 'surface', tone: 'min' },
});The text color above has no contrast floor, so its ratio follows its tone
step: 6.29:1 in light and 4.85:1 in dark. Add contrast when the measured
ratio matters.
Tone is the contrast solver’s search axis because it is contrast-uniform: the search converges quickly and WCAG gets a closed-form first probe. But Glaze never assumes a chromatic color has the luminance of the gray at its tone. It measures the real color.
contrast takes one spec with a pluggable metric: a WCAG ratio (a bare number,
a preset such as 'AA', or { wcag }) or an APCA Lc target ({ apca }).
Forms, presets, roles, and high-contrast escalation are covered in
Contrast solving and
Contrast and high contrast.
For a color with base and contrast, in each scheme Glaze:
- resolves the base and the color’s preferred tone for that scheme, clamped into the scheme’s tone window (anchored extremes excepted);
- measures the requested WCAG ratio or APCA Lc at the preferred tone, using the
color’s real hue and saturation — if it already clears the floor with a
small margin (×1.01 for a WCAG ratio, +0.5 Lc for APCA, to absorb rounding
in the output formats), the tone is kept (
contrastis a floor, not a target); a preferred tone that clears the floor but not the margin is also kept, and counts as met, when no searched side meets the floor (white text at tone 100 has nowhere further to go); - otherwise searches tone. For WCAG the search first measures the gray tone
whose luminance hits the ratio exactly —
Y = R * (Y_base + 0.05) - 0.05on the lighter side,(Y_base + 0.05) / R - 0.05on the darker — which only narrows where the binary search against the measured chromatic luminance looks, so a chromatic color still lands on its own crossing. For APCA it binary-searches against the Lc target directly. The search covers the full 0–100 range, so a demanding floor can push a color past the window, and it aims for the same margin past the target; - warns when the target is physically unreachable in the scheme.
import { glaze } from '@tenphi/glaze';
const theme = glaze(150, 90);
theme.colors({
surface: { tone: 97, saturation: 0 },
// 49.4 tones below the surface: exactly 4.5:1 for a neutral
'step-text': { base: 'surface', tone: '-49.4' },
// Same starting tone, but the solver measures the real color
'floor-text': { base: 'surface', tone: '-49.4', contrast: 'AA' },
});apcaContrast(yText, yBg) implements APCA-W3 0.1.9 (simplified SAPC): a
soft clamp for low luminances and separate exponents for normal and reverse
polarity, returning a signed Lc whose magnitude the solver compares with the
target. Its inputs are APCA screen luminances over the gamma-encoded sRGB
channels, not WCAG relative luminance:
Ys = 0.2126 * R^2.4 + 0.7152 * G^2.4 + 0.0722 * B^2.4The soft-clamp constants are calibrated against Ys, so the solver feeds APCA
that basis. The function it uses is exported as
apcaLuminanceFromLinearRgb,
so apcaContrast over its output reproduces the solver’s own Lc. The
implementation omits APCA’s font-size lookup that maps an Lc to
a usable text size.
After all four scheme passes, Glaze verifies every color that has a base and
a contrast floor. It re-measures the color against its base in each scheme, in
the floor’s own metric (APCA screen luminance for APCA, WCAG luminance for
WCAG) and with each variant’s own pastel flag, and emits a console.warn when
the result drifts below the target by more than a small slack: 2% of a WCAG
ratio, or 1.5 Lc. It skips a scheme where the solver couldn’t reach the floor,
which already has the solver’s “cannot meet” warning with the same measured
value, and an achromatic color (saturation 0), whose luminance is exactly its
tone’s. Because the solver already measures the real chromatic color, a floor
it meets passes this check, so in practice the advisory stays silent; it
remains as a safety net for the chromatic approximation. Warnings are
deduplicated through a 256-key session cache that starts over when full. Both
warnings are listed in Configuration.
Glaze parses OKHST wherever it takes a color value — glaze.color(), a color
definition’s from, and the bg / fg of the standalone glaze.shadow() /
glaze.glow():
import { glaze } from '@tenphi/glaze';
glaze.color('okhst(152 95% 70%)');
glaze.color({ h: 152, s: 0.95, t: 0.7 });Both value forms reproduce the color exactly in the light scheme. The
structured form glaze.color({ hue: 152, saturation: 95, tone: 70 }) is
different: its tone is an authored tone on the 0–100 scale, mapped through the
light window like a theme color, so it renders at tone 71.48. See
Color tokens.
There is no native CSS okhst() function, so native exports use oklch,
rgb, or hsl. Tasty can consume Glaze’s custom
serialization, so tasty() accepts format: 'okhst', as does glaze.format()
for a single variant. tokens(), json(), css(), and tailwind() throw and
name a native format instead; the DTCG exports pick a color space of their own.
const theme = glaze(280, 30);
theme.colors({ surface: { tone: 97 } });
theme.tasty({ format: 'okhst' });
// {
// '#surface': {
// '': 'okhst(280 30% 97.15%)',
// '@media(prefers-color-scheme: dark)': 'okhst(280 27% 11.85%)',
// },
// }The color formats are listed in
Output formats; toTone, fromTone,
toneFromY, yFromTone, okhstToOkhsl, okhslToOkhst, variantToOkhsl, and
REF_EPS are exported for your own math (see
Utilities).
When you move raw CSS colors or design tokens into Glaze, preserve the source
colors first: glaze.fromHex() and glaze.fromRgb() seed a theme from a
color, glaze.color() takes any color value, and a color definition’s from
places a literal color inside a theme. Then replace one-off values with root
tones, tone deltas, and contrast floors as the relationships become clear.
To carry an OKHSL lightness L (0–100) over as a tone, convert it with
toTone(L / 100); the two are not the same number. That tone is still an
authored tone, so the light window remaps it and it renders slightly lighter:
L 20 becomes tone 14.36 and renders at lightness 23.8. To keep a source color
exact in light, place it with from, which skips the light window, or turn the
window off with lightTone: false. The full workflow is in
Migration and upgrading.