Custom properties as a constrained design system

CSS custom properties are most commonly used for design tokens: colors, fonts, spacings, timings, and other atomic design values drawn from a shared palette. Pulling values only from tokens tends to produce clean, consistent design. That same effect explains much of the popularity of utility class frameworks — choosing from a limited, pre-designed set of values keeps the result from going off the rails.

A stylesheet that defines one-styling-job tokens offers a similar value proposition to a utility framework:

<h1 class="color-primary size-large">Header<h1>

…is analogous to:

html {
  --color-primary: green;
  --size-large: 3rem;
  /* ... and a whole set of tokens */
}

h1 {
  color: var(--color-primary);
  font-size: var(--size-large);
}

Both approaches exist with and without a build step. Tachyons is an it-is-what-it-is utility stylesheet; Windi CSS adds a just-in-time compiler and more. Pollen is an it-is-what-it-is library of custom properties; the newer Open Props ships a just-in-time compiler that delivers only the custom properties in use.

How Open Props works

Open Props is a large collection of CSS custom properties to design with — a starting point for styles, applying custom properties everywhere but within the familiar limited set of design tokens.

Open Props: A new CSS library by the amazing @argyleink.

It's Tailwind but with CSS variables.https://t.co/21pxE2bjW7

— David East (@_davideast) December 1, 2021

The main draw is the defaults. What it deliberately does not do is remove the need to name things, which utility-class users tend to enjoy. You still select and style elements with ordinary CSS selectors and named classes; the difference is that values are plucked from the provided custom properties rather than hand-crafted.

Size and just-in-time delivery

The base package (source on unpkg) is about 4.4kb over the wire, per DevTools measurement. That excludes the CSS you write to consume the properties. Additional PropPacks add to the size, though they too are very small. When size matters, the just-in-time compiler is the answer; it can be tried on StackBlitz.

Because it is ultimately regular CSS, nothing is off limits, and it should keep working as CSS evolves. Its limits are simply those of bespoke CSS using largely pre-designed values.