Colors

A few inputs, set anywhere, and a small set of colours derived from them on every element. Pick any colour, put it on any element, and everything inside re-themes around it.

alpha The class names and states here are stable. The look is not: these styles can change in a minor release, without a major version bump.

Inputs

ClassDoes what
--primaryThe brand colour. Its own hue and chroma are kept; only the lightness is pinned per role
--secondaryLinks. Defaults to the primary
--neutralWhat text and surfaces are tinted with. Defaults to a near-grey on the primary's hue
--errorInvalid fields, error text, error alerts

Live preview

Change these and every page on this site updates. Values persist for the session.

Derived colours

Components read these, never the inputs. Text colours are solid, so their contrast never depends on what sits behind them. The page (--bg) sits a step below what's raised off it (--surface); soft fills and hairlines are a tinted mid-tone mixed in, so they carry the theme's colour and flip with the scheme on their own. The names are the ones the apps built on this library already use.

--bg Page
--surface Cards, rows, sheets, fields
--fill Soft fill, 30%
--fill-strong Soft fill, 63%
--line Hairlines
--edge Borders that must show: fields, focus
--ink Text
--muted Secondary text
--faint Disabled text
--accent Filled button
--accent-ink Text on it
--accent-text Brand text
--link Links
--good Success text
--warn Warning text
--bad Error text

Apply anywhere

Set an input on any element and add .retheme, and everything inside re-themes around it. The class marks where colours are derived again; between boundaries they are simply inherited, so you can also override a single derived colour, such as --fill, for a whole subtree. These are nested sections, each setting a single input:

Same markup in both builds
<section class="card-border retheme" style="--primary: tomato">
  <p><code>--primary: tomato</code></p>
  <button class="btn">Save</button>
  <input class="input" placeholder="A field" style="margin: 0.75rem 0" />
  <section class="card-border retheme" style="--primary: #0a7d6b">
    <p><code>--primary: #0a7d6b</code>, one level down</p>
    <button class="btn btn-secondary">Cancel</button>
    <a href="#" class="link">A link</a>
    <section class="card-border disabled" style="margin-top: 0.75rem">
      <p><code>.disabled</code>: one declaration, <code>--chroma: 0</code></p>
      <button class="btn">Save</button>
    </section>
  </section>
</section>

Brand colours keep their character

Only the lightness is pinned per role. A muted brand stays muted and a grey one stays grey, where 2.x kept only the hue and replaced the chroma. Chroma is still capped per role, so a vivid colour at a very light or very dark lightness stays in gamut.

Same markup in both builds
<div class="flex" style="flex-wrap: wrap">
  
    <div class="retheme" style="--primary: rebeccapurple; display: flex; flex-direction: column; gap: 0.5rem; align-items: start">
      <button class="btn">rebeccapurple</button>
      <button class="btn btn-secondary">Secondary</button>
      <span class="badge">Badge</span>
    </div>
  
    <div class="retheme" style="--primary: #c2410c; display: flex; flex-direction: column; gap: 0.5rem; align-items: start">
      <button class="btn">#c2410c</button>
      <button class="btn btn-secondary">Secondary</button>
      <span class="badge">Badge</span>
    </div>
  
    <div class="retheme" style="--primary: #6b7c59; display: flex; flex-direction: column; gap: 0.5rem; align-items: start">
      <button class="btn">#6b7c59</button>
      <button class="btn btn-secondary">Secondary</button>
      <span class="badge">Badge</span>
    </div>
  
    <div class="retheme" style="--primary: slategrey; display: flex; flex-direction: column; gap: 0.5rem; align-items: start">
      <button class="btn">slategrey</button>
      <button class="btn btn-secondary">Secondary</button>
      <span class="badge">Badge</span>
    </div>
  
    <div class="retheme" style="--primary: #1d4ed8; display: flex; flex-direction: column; gap: 0.5rem; align-items: start">
      <button class="btn">#1d4ed8</button>
      <button class="btn btn-secondary">Secondary</button>
      <span class="badge">Badge</span>
    </div>
  
</div>