Counter
A number controlled entirely through CSS state and events.
Each click rolls a new hue and picks a new name.
Press New color, or Tab to it and press Enter or Space.
| name | value | previous | changes |
|---|---|---|---|
| Waiting for the preview to start. | |||
Random values at event time. Inside an :on() mutation, random() and pick() are evaluated at each event, so every click gives a new hue and a new word.
Native random() (where the browser supports it) gives each element a random value when styles are computed, and Reactive CSS leaves such calls to the browser. Rolling a new value on a click is what needs the runtime, or JavaScript.
random() and pick() outside a mutation are rolled once, not on every event./* ---- Reactive CSS -------------------------------------------------------------------------- */.random { --hue: state(200); --mood: state("calm"); }/* random() and pick() inside a mutation are rolled again at every click. */.random .roll:on(click) { --hue: set(random(0, 359, 1)); --mood: set(pick("calm", "bold", "bright", "soft"));}.random .swatch { background-color: hsl(var(--hue) 80% 55%); }.random .hue { content: var(--hue); }.random .mood { content: var(--mood); }Source: site/src/catalog/api/random-colors/. style.css from its Reactive CSS divider; the layout above it and the shared api.css run but are not shown.
A number controlled entirely through CSS state and events.
Type in the field and the preview follows; the Clear button resets both.