Themes
A theme sets the colors by purpose, such as the text, background, and status colors, and the colors of every component.
Choosing a theme
Load one stylesheet from styles/themes/ after style.css. This site loads auto-stark.
<link rel="stylesheet" href="https://assets.nercone.dev/style.css">
<link rel="stylesheet" href="https://assets.nercone.dev/styles/themes/auto-stark.css">Choose a theme to see it on this site. The choice is saved in this browser and applies to every page.
Themes
There are four base themes. dark and black differ only in the background, and so do light and white.
| Theme | color-scheme | --color-stark | --color-background | --color-background-alt |
|---|---|---|---|---|
dark | dark | white | grey-10 | grey-20 |
black | dark | white | grey-0 | grey-10 |
light | light | black | grey-190 | grey-180 |
white | light | black | grey-200 | grey-190 |
The text, layers, and borders are translucent stark: --color-foreground is {white|black}-opacity-75, --color-foreground-alt is -opacity-100, --color-layer and --color-layer-alt are -opacity-5 and -opacity-10, and --color-border and --color-border-alt are -opacity-10 and -opacity-15.
UD variants
dark-ud, light-ud, black-ud, and white-ud are the same as the base themes, except that the status and alert colors are JIS safety colors. Their colors are chosen to be told apart by people with color vision deficiencies, and keep the same color in every theme.
| Colors | Base themes | UD themes |
|---|---|---|
information, note | sky | jis-blue |
success | green | jis-green |
tip | green | jis-blue |
warning | orange | jis-red-yellow |
error, caution | red | jis-red |
important | purple | jis-red |
In the UD themes, -dark, -normal, and -bright of each status are the same color.
The JIS safety colors are never made lighter or darker, not even on hover: some people, such as those with achromatopsia, tell them apart only by their lightness, so a changed lightness can be read as another color. On the light backgrounds, most of them do not reach the contrast of WCAG 2.2 AA (4.5:1) as text, so the UD themes do not use them as text. Status buttons, toasts, alert titles, and <mark> are filled with the safety color and written in jis-black, which has at least 4.8:1 on every safety color the UD themes use. White text was not chosen because it reaches 4.5:1 on none of them (jis-blue comes closest with 4.3:1), and darkening the colors was not chosen because it changes their lightness. A status button shows hover with --color-foreground-alt on its border instead of a darker fill. The borders of text fields, dropdowns, and swatches are 60% of --color-foreground, so that they reach 3:1 against the page (WCAG 2.2, 1.4.11); the base themes keep the thinner border.
Known exceptions: a disabled control is drawn at 50% opacity, which also changes the lightness of a JIS safety color, and the tint of layer-* is 10% of it. WCAG does not require contrast for disabled controls.
Contrast
All themes aim for 4.5:1 for text, as WCAG 2.2 AA requires. The UD themes also give the borders of text fields, dropdowns, and swatches 3:1 (1.4.11); the base themes keep a thinner, more modern border, which stays below it. In the base themes, -bright of each status is the color for text, so the light themes use a darker step of the hue than the dark themes.
| Hue | -bright in light, white | -bright in dark, black |
|---|---|---|
sky | sky-55 | sky-bright |
green | green-40 | green-bright |
orange | orange-50 | orange-bright |
red | red-65 | red-120 |
purple | purple-75 | purple-130 |
Each step is the lightest (in the light themes) or darkest (in the dark themes) of the steps of 5 that keeps 4.5:1 with some room, measured against the page, against --color-background-alt under the 10% tint of a toast, against the 10% tint of a button or layer, and against a button on hover. The placeholder of a text field is 80% of --color-foreground for the same reason.
Automatic themes
These follow the color scheme of the system with prefers-color-scheme.
| Theme | Light | Dark |
|---|---|---|
auto | light | dark |
auto-stark | white | black |
auto-ud | light-ud | dark-ud |
auto-stark-ud | white-ud | black-ud |
In the files, the automatic themes import the two themes with a media query. The server joins the imports, so each is one stylesheet.
@import url("./light.css") (prefers-color-scheme: light);
@import url("./dark.css") (prefers-color-scheme: dark);Current colors
The colors by purpose of the current theme. Click a swatch to copy it.
block-note
block-tip
block-important
block-warning
block-caution
Changing the theme with a script
theme.js changes the theme while the page is open. It adds {baseURL}{theme}.css after the other stylesheets, removes the stylesheet it added before once the new one has loaded, and sets data-theme on <html>. Stylesheets in the HTML stay, so keep loading a theme there as well: it is used until the script runs, and when JavaScript is disabled.
Clicking an element with data-theme-trigger="light" applies that theme, and data-theme-trigger="" removes the theme added by the script. Radio buttons and checkboxes with data-theme-trigger are checked while their theme is applied.
<button type="button" data-theme-trigger="light">Light</button>
<label><input type="radio" name="theme" data-theme-trigger="dark">Dark</label>const theme = window.nercone.get('theme');
await theme.set('light'); // true when applied, false when the name is unknown or the stylesheet failed to load
theme.get(); // 'light'
await theme.set(null); // removes the stylesheet added by theme.jsOn load, theme.js applies the first theme it finds in this order: the one saved in localStorage, the one in <html data-theme="…">, and the theme option. Names that are not in the themes option are skipped. set() saves the theme unless it is called with { save: false }.
| Option | Default | Description |
|---|---|---|
baseURL | 'https://assets.nercone.dev/styles/themes/' | Where the theme stylesheets are. A relative URL is resolved against the page when the instance is created |
themes | The 12 themes above | Names that can be applied |
theme | 'auto-stark' | The theme applied when none is saved or set on <html> |
storageKey | 'nercone-theme' | The localStorage key. An empty value disables saving |
rootAttribute | 'data-theme' | The attribute set on <html> |
triggerAttribute | 'data-theme-trigger' | The attribute of the elements that change the theme |
linkAttributes | { 'data-view-transition-keep': '' } | Attributes of the added <link>. The default keeps it when view-transition.js moves to another page |
To change the options, register a new instance under the same name. See Scripts.
window.nercone.register('theme', new window.nercone.Theme({
baseURL: '/styles/themes/',
theme: 'auto',
storageKey: ''
}));Making a theme
A theme is a :root rule that sets color-scheme, --color-stark, every color by purpose and component color, and three other variables: --alert-title-padding-inline, the padding that goes with the fill of an alert title, and --button-status-hover-background-mix and --button-status-hover-border-mix, how much the hover of a status button changes its background and border. Start from a copy of the theme closest to the one you want, and change the colors by purpose first: the component colors refer to them, so most of them follow without changes. Every theme must define the same variables, because a missing one leaves the components that use it without a color.
:root {
color-scheme: dark;
--color-stark: var(--color-white);
--color-foreground: var(--color-white-opacity-75);
--color-foreground-alt: var(--color-white-opacity-100);
--color-background: var(--color-blue-5);
--color-background-alt: var(--color-blue-10);
/* … */
}