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

Overrides

How to change a Vanilla Breeze default: switch a theme, adjust a token, or write plain CSS. Library styles sit in cascade layers, so a rule you write outside a layer wins.

Why your CSS wins

Vanilla Breeze puts every rule it ships inside a named cascade layer:

CSS gives rules outside any layer priority over rules inside one, whatever the specificity of either and whichever stylesheet loads first. So a plain rule in your stylesheet beats the library's rule for the same property.

The four levels below build on this. Use the first one that does the job. Where to change something has the short version as a table.

Two exceptions

  • Declarations the library marks !important. For important declarations the layer order runs the other way, so these beat your CSS, including your own !important. The library uses them for rules that must hold: [hidden] and the other visibility attributes stay hidden, some layout structure cannot be undone by accident, and the print and forced-colors resets apply. If a property will not change, look for one of these in the developer tools and use the attribute or token the component offers.
  • Rules you put in a layer. A rule inside @layer no longer has the priority of unlayered CSS. See What not to do.

Level 1: switch the theme

Set data-theme on any element to give that part of the page another theme. Everything inside takes the theme's colors, type, shape and shadows.

A theme is a set of custom property values, and custom properties inherit, so each element uses the values from its nearest ancestor with a data-theme. Themes nest to any depth. A themed region also paints its own background and text color.

The theme's stylesheet must be loaded. Modern, Minimal, Classic and the accessibility themes are in the main bundle. The others are separate files: see Using themes.

The same card markup gives three results: the default tokens, Swiss (red, sans-serif, square) and Cyber (cyan, monospace, dark). The last example nests Swiss, Cyber and Swiss again.

Level 2: adjust tokens

Keep the theme and change a few of its values for the page or for one region. Set the custom properties on an element and everything inside uses them.

Colors need one more step

Links and buttons read --color-interactive, and that token is computed from --color-primary on the root element. Changing --color-primary on a region does not change it. Set both, with their hover values:

On :root this step is not needed, because the derived tokens are computed there. For a region, data-accent or a small theme of your own does the same with less CSS. Color: The brand color covers both.

The first card is standard Swiss. The second changes the primary and interactive colors to purple and nothing else. The third changes color, radius and shadow together, and the typography is still Swiss.

Level 3: plain CSS

When no token covers the change, write a rule. It wins because it is not in a layer. Use this to change one property of one element, or to style something the library does not have.

Use the tokens inside your own rules. Their values come from whatever theme and mode apply where the element sits, so your component changes with the page.

The left column is the Swiss default. The right column is the same markup with unlayered classes: a purple rounded card, an italic pull quote and a pill button, with no !important.

Level 4: let the elements follow the tokens

Often no override is needed. Vanilla Breeze has no utility-class layer: apart from a few typography helpers and .visually-hidden there are no .bg-*, .text-* or .p-* classes. Each element reads its color, type, spacing and shape from tokens, so the same markup follows the theme where it sits.

Neither the badge nor the button has a color class. Each reads the theme's interactive color, so it is red in one section and cyan in the other.

Writing your own helpers

If you want single-purpose helper classes, write them against tokens and put them in a layer of your own. A layer first named after the library's stylesheet has loaded sits above the library's layers, and below your unlayered rules.

Order matters here. If your stylesheet loads first, helpers becomes the lowest layer and loses to every library rule.

Combining the levels

The levels work together on one page. This demo is a magazine layout that uses all four:

  • Level 1: Swiss for the page, with a Cyber theme on the subscribe panel
  • Level 2: a muted primary color in the long-read section
  • Level 3: a pull quote and an author byline written as unlayered CSS
  • Level 4: <user-avatar>, <strong> and <small> in the byline, with no styling classes

What not to do

Do not reach for !important

If your rule is not winning, first check that it is outside any @layer. An unlayered rule beats every normal library declaration. If it still loses, the library has marked that declaration !important on purpose (see the exceptions), and adding your own will not beat it.

Do not write overrides inside the library's layer names

If you write @layer custom-elements (or any other name from the list above) in your stylesheet, your rules join that layer. They then compete with the library's rules by specificity and source order, and lose to every later layer.

Do not hard-code a value when a token exists

A fixed value stops following the theme and the mode.

Decision guide

Situation Approach
A whole section needs a different identity data-theme on the section
Same theme, different brand color in one place data-accent, or the primary and interactive tokens together
Same theme, different corners, shadow or spacing The token on :root or on the region
One property of one element needs to change An unlayered rule
A component the library does not have An unlayered class, written with tokens
The same one-line adjustment in many places A token-based helper class in your own layer
You think you need !important Check that your rule is unlayered, then look for a library !important on that property

Compared with a utility-first framework

A utility-first framework such as Tailwind CSS and Vanilla Breeze put the styling decision in different places. Neither is wrong. The table shows what to expect if you are moving from one to the other.

Utility-first Vanilla Breeze
Starting point Elements are reset to a plain baseline Elements are styled by their tag
Where a style is written Utility classes in the markup Tokens and CSS rules; markup carries element names, variant classes and data-* settings
Changing a look Edit the classes on the element Change a token or a theme, or write a rule
Build step A build generates the CSS for the classes in use None: one stylesheet, linked as is

The two can share a page. Utility classes written outside a layer win over the library's rules like any other unlayered CSS.

↑