Skip to main content

Theme scopes and cascade

The web app has a light theme and a dark theme, and a stylesheet that changes colors has to know how the two are told apart and which declaration wins when several set the same property. This page describes both.

The light and dark themes​

The user picks a theme in the settings, and UI_DEFAULT_THEME sets the theme that a new user starts with (Web app configuration). Several mechanisms make the choice take effect:

MechanismWhat it does
The dark class on <html>The class is present in the dark theme and absent in the light theme.
@custom-variant dark in frontend/src/index.cssThis declaration makes the dark: variant of a Tailwind utility follow that class.
<meta name="color-scheme">The content of this element is dark or light, to match the theme.
:rootA declaration on :root sets the light value of a custom property.
.darkA declaration on .dark sets the dark value. A property that .dark does not declare keeps its :root value in the dark theme.
data-font-size on <html>The attribute is medium or large, from the user's Font size setting, and the rule :root[data-font-size="large"] sets --text-scale.
.force-lightThis class redeclares a subset of the properties for the elements inside it, so that they stay light in either theme. The login form and the select menus use it.

The class .force-light redeclares these properties:

--general-border-primary, --general-border-secondary, --general-bg-primary, --general-bg-secondary, --general-label, --general-label-hover, --general-label-disabled, --btn-secondary-bg, --btn-secondary-border, --btn-secondary-bg-hover, --btn-secondary-bg-disabled, --dropdown-border, --dropdown-bg, --dropdown-shadow, --input-bg, --input-bg-hover, --text-heading, --text-subtitle, --text-body, --text-caption, --text-support

How the cascade resolves a property​

The selectors :root and .dark have the same specificity, so the declaration that comes later in the cascade wins. In tokens.css, .dark comes after :root. Four rules follow from this:

  • The theme stylesheet that WL_STYLESHEET names loads after the base stylesheets, so it wins at equal specificity. A rule on :root in that stylesheet also applies in the dark theme, because it comes after the .dark rule of tokens.css. To give a property one value in each theme, declare it on :root and then on .dark, in that order.
  • The applied theme preset comes after that stylesheet in the same way. Its light values form a :root rule, and its dark values form a .dark rule.
  • A rule on .dark alone changes the dark theme only.
  • A custom property that refers to another with var() follows the other property. When --color-light-100 changes, every property whose value is var(--color-light-100) changes with it, and so does every class that names the step, such as bg-light-100.