Documents v0.10.0 · previews run the real runtime · experimental features are marked exp

Computed custom properties

declarationsince 0.10experimentalrequires runtime

--clean: trim(--value): a custom property whose whole value is one value function is also a read-only state, computed from other states.

On this page · 8 sections+

Syntax

--<name>: <value function>(...);--<name>: live(<value function>(...) [, <interval>]);

registry syntax: --name: value-function(…) | live(value-function(…) [, interval])

Parameters

value functionlength, includes, lower, trim, format, timezone; time inside live()required
The call must be the whole value. It may read only states, literals and other value functions.

Effect

A read-only state of that name on each matched element, and the same value as a CSS custom property.

Example

chain.cssreactive
.form { --value: state(""); --clean: trim(--value); --chars: length(--clean); }.form textarea:on(input) { --value: set(event(value)); }.form .count { text: var(--chars); }.form:when(--chars > 140) .count { color: red; }
state()Function · hover any red tokenMakes each matching element the owner of an independent state with an initial value.Reference →

Behavior

  • Updates. Recomputed synchronously when a state it reads changes, inputs before what reads them, before the change returns. An unchanged result notifies nobody. previous() never sees an intermediate value.
  • Owner. Each matched element owns one, while it matches. Consumers use the nearest owner, as for state().
  • Read-only. set(), toggle() and other mutations, legacy on: actions and bind: input change nothing, with a diagnostic.
  • Errors. An evaluation error keeps the last value, with a diagnostic. A missing input gives no value, reported after a second.

Supported contexts

  • An unconditional style rule. @layer and nesting in an unconditional parent are allowed.

Limitations

  • Not a general CSS cascade. The value is written inline on each owner. CSS shows the state on the owner unless !important or @property overrides it, and inside the owner unless another declaration of the name applies there.
  • A declaration of the same name in a processed stylesheet (one with reactive syntax), including state() and @property, turns the name off, with a diagnostic. In a stylesheet without reactive syntax, and for inline styles inside an owner, only development builds report it. Cross-origin stylesheets and shadow roots cannot be checked.
  • In :when(), state pseudo-class, pseudo-element, @media, @supports or @container rules, and with !important, the declaration stays CSS-only, with a diagnostic. So does one that reads attr(), event(), element(), random() or time() outside live().
  • Names that read each other are rejected.
Experimental · syntax may change between minor versions