Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

Color

How color works in Vanilla Breeze: tokens named for their role, a brand color derived from one hue, light and dark values for every token, and status colors.

Colors are named for their role

Every element takes its colors from tokens that say what the color is for, not what it looks like. A card uses --color-surface and --color-text, never white and near-black. That is what lets one page work in light and dark, and under any theme, with no change to its markup.

Use the same tokens in your own CSS. The groups below cover almost every need. Tokens: Colors has the full list with values.

Role Tokens Use for
Surfaces --color-background, --color-surface, --color-surface-raised, --color-surface-sunken The page, a panel on it, something lifted above the panel, and a well set into it. See Surfaces.
Text --color-text, --color-text-muted, --color-text-subtle Body text, secondary text, and hints or placeholders
Borders --color-border, --color-border-strong, --color-border-subtle Dividers and outlines. These are decorative. The edge of a form control uses --control-border, which is darker.
Interactive --color-interactive, --color-interactive-hover, --color-interactive-active Links, buttons and anything else that can be operated. They follow the primary color unless a theme sets them apart.
Brand --color-primary, --color-secondary, --color-accent, each with -hover and -subtle Places where the brand color is the point: a highlighted badge, a hero band, a chart series
Status --color-success, --color-warning, --color-error, --color-info, each with -subtle and -text Messages and states. See Status colors.

Move the slider and every brand-colored part follows: the buttons, the link, the badge and the hover shade. Switch the mode and the surfaces, text and borders change with it. The status messages keep their own hues.

The brand color

The primary color is built from three seeds: a hue, a lightness and a chroma, in the OKLCH color space. The hover, active and subtle shades are computed from the result, so you set the seeds and get the rest.

Seed Default Notes
--hue-primary260An angle from 0 to 360. Also tints the dark surfaces.
--lightness-primary50% in light, 65% in darkThe library raises it in dark mode so links and buttons keep their contrast
--chroma-primary0.2 in light, 0.18 in darkHow vivid the color is
--hue-secondary, --hue-accent200, 30Each has its own --lightness-* and --chroma-* seed

Set a hue

For most sites one line is enough. The default lightness and chroma were chosen for AA contrast with the default hue, and perceived brightness varies a little by hue, so check links and buttons in both modes after a change. If one falls short, adjust --lightness-primary.

The ten accents are presets of the same seeds, applied with data-accent and no CSS.

Set an exact color

If you must match a specific color, set --color-primary itself. The hover, active and subtle shades are still derived from it. The seeds no longer apply, so give a lighter value for dark mode with light-dark() and check the contrast of both.

The second selector keeps your color inside a region that has its own data-mode. Without it, the library computes the primary color from the seeds again on that element.

In one region

Set seeds on :root, or on an element that has data-theme, data-mode or data-accent. Those are the elements on which the library computes the derived colors. A seed set on any other element changes nothing, because the colors were already computed further up. How a token change reaches an element explains why.

Light and dark

The page declares color-scheme: light dark, and each semantic token holds two values in a light-dark() function. With no attribute and no script, the page follows the reader's system setting.

Markup Result
<html>Follows the system setting
<html data-mode="light">Light, whatever the system says
<html data-mode="dark">Dark, whatever the system says
<aside data-mode="dark">A dark region on a page of either mode

A region with its own data-mode paints its own background and text color, so a dark panel on a light page is readable without further CSS. The same is true of a region with its own data-theme.

What dark mode changes

  • Surfaces, text and borders take their dark values. The dark surfaces carry a faint tint of the primary hue (--chroma-surface-tint, 0.02).
  • The primary color becomes lighter and slightly less vivid. The -subtle shades of the primary, secondary and accent colors change from a pale tint to a deep one, so text in --color-text stays readable on them.
  • Status colors keep their hue. Their -subtle and -text values swap, so a message is dark with light text.
  • The shadow tokens get stronger, since a faint shadow does not show on a dark page.

Your own colors in both modes

Prefer a token. When you need a color the tokens do not have, write both values with light-dark(). It follows data-mode and the system setting the same way the tokens do, including inside a scoped region.

A switch for readers

<settings-panel> and <theme-picker> include a mode control and remember the choice. To build your own, call ThemeManager. It writes data-mode on <html> and stores the preference.

Status colors

Each of the four statuses has three tokens. Use them as a set.

Token Use for
--color-success, --color-warning, --color-error, --color-infoBorders, icons, dots and filled badges
--color-success-subtle and the other threeThe background of a message
--color-success-text and the other threeText on the matching -subtle background, or on a surface

Do not set body-size text in the base color. --color-warning in particular is too light to read on a light surface. The library's own parts follow the same split: <status-message>, data-callout and the <layout-badge> colors all read these tokens. Color alone should not carry the status, so pair it with a word or an icon.

Text on a colored fill

A <button> works out its own label color. It picks black or white, whichever contrasts more with the fill, and picks again for the hover and active fills. That holds for the theme's color and for a color you pass in --btn-color.

For a fill of your own in the primary or interactive color, --color-text-on-primary and --color-text-on-interactive do the same: each is black or white, whichever contrasts more with its fill, in every browser, theme and mode. That gives at least 4.5:1 unless a theme sets the token to a color of its own.

For the other colors, the library defines a set of tokens with the same behavior in browsers that support contrast-color(): --color-text-on-secondary-auto, and the same for accent, success, warning, error and info (and for primary and interactive). They are undefined elsewhere, so always give a fallback.

Tints and state colors

A few more tokens are mixed from the ones above, so they follow the theme and the mode without values of their own.

Tokens What they are
--tint-primary-5, -10, -20, -30The primary color at 5% to 30% opacity, for washes and highlights
--surface-hover, --surface-focus, --surface-active, --surface-selectedThe surface color with a little of the interactive color mixed in
--color-hover-bg, --color-hover-text, --color-active-bg, --color-active-textHover and current-item colors for menus, navigation links, list items and table rows. A theme changes all of those by setting these four.
--color-overlay-subtle, -medium, -strongTranslucent black or white for scrims over content
--color-row-stripeThe alternate row wash for table[data-striped]

Contrast

The text tokens are tested for AA contrast against the surface tokens under each bundled theme, in light and dark. That holds while you pair tokens as this page describes. Any color you introduce is yours to check. Accessibility: Color lists the pairs and the ratios, and the high contrast theme raises them to AAA.

↑