Skip to Content
Documentation

Make a theme

Write a theme's dark and light looks, its colour tokens and the forms a colour takes, and the rules every look must meet.

A theme sets the colours the apps draw. Songstress's own look is the only one an app carries: every other theme is an extension's, which an admin installs, and each member picks from the themes installed there. A theme is data: it needs no entry and no permission. Start one with npm create songstress-extension@latest -- --theme.

Declaring a theme

Up to 20 themes an extension, each with its looks written in the manifest, or in a theme file whose path it names, never both:

songstress.json
"contributes": {
  "themes": [
    { "id": "mocha", "label": "Catppuccin Mocha", "appearance": "dark", "dark": { "colors": { "background": "#1e1e2e", "text": "#cdd6f4", "accent": "#cba6f7" } } },
    { "id": "nord", "label": "Nord", "appearance": "both", "path": "themes/nord.json" }
  ]
}

Prop

Type

A theme file holds dark, light or both, written as the manifest would, and exactly the looks its theme's appearance names. It is at most 16 KiB, read as strictly as the manifest is:

themes/nord.json
{
  "$schema": "https://songstress.app/schema/theme/v1.json",
  "dark": { "colors": { "background": "#2e3440", "text": "#eceff4", "accent": "#88c0d0", "border": "rgb(236 239 244 / 12%)" } },
  "light": { "colors": { "background": "#eceff4", "text": "#2e3440", "accent": "hsl(212, 42%, 40%)" } }
}

Looks

A phone in dark mode shows a theme's dark look, and one in light mode its light look; Android shows the dark look when there is one. The web and desktop apps show the appearance their person picks. A person may take the dark look of one theme and the light look of another.

Prop

Type

A look of one seed is a whole theme: the seed is the accent, and the stage and the text take a little of its hue.

The tokens

Prop

Type

Only border and surface.hover may be translucent. The tokens are few on purpose: each is a role many parts of the apps share, never one control's.

Colours

A colour is written in any of these forms, as CSS writes them:

  • hex: #RGB, #RGBA, #RRGGBB or #RRGGBBAA, in either case;
  • rgb() and rgba(): three channels, each 0 to 255 or 0% to 100%, and an optional alpha, between commas (rgb(108, 182, 255)) or between spaces with the alpha after a slash (rgb(108 182 255 / 50%));
  • hsl() and hsla(): a hue in degrees or as an angle (deg, grad, rad, turn), a saturation and a lightness from 0% to 100%, and an optional alpha, written as rgb()'s are.

An alpha is 0 to 1 or 0% to 100%. A function's name is lowercase, and a colour is at most 64 characters. A name (red), currentColor, var(), a gradient and other colour spaces (oklch()) aren't colours a theme writes.

Each colour is read into one form, #rrggbb, or #rrggbbaa below full alpha. A translucent colour anywhere but border and surface.hover is refused (THEME_COLOR_ALPHA), as a colour in no form is (THEME_COLOR). songstress/theme reads them as the apps do:

check-colours.ts
import { normalizeLook, parseColor } from 'songstress/theme'

console.log(parseColor('hsl(212, 42%, 40%)'))
console.log(normalizeLook({ colors: { background: '#2e3440', text: '#eceff4', accent: '#88c0d0' } }))

What a look leaves out

An app fills every token a look leaves out, from the look's own colours where it can:

  • the seed, for the accent and the tint of the stage and the text;
  • surface from the background with 8% of the text in it, and sidebar as the surface;
  • surface.raised from the surface with 6% of the text, border with 12%, and surface.hover as the text at 8%;
  • text.muted and text.faint from the text, 30% and 50% of the way to the background;
  • accent.fill from the accent; accent.onFill as white or near black, whichever reads; and accent.fill.pressed from the fill, moved 16% away from its label.

Anything else comes from Songstress's own look of the same appearance. So a look of three colours is a whole theme.

The rules

A look is shown only if it meets these, once it is filled. Contrast is WCAG 2's ratio.

  • The background's relative luminance is under 0.10 in a dark look and over 0.55 in a light one.
  • text on background, surface, surface.raised and sidebar: 4.5:1.
  • text.muted on background and surface: 4.5:1.
  • text.faint on background: 3:1. On surface: 3:1, and 2.9:1 in a light look.
  • accent on background: 4.5:1. On surface: 3:1.
  • success and warning on background and surface: 4.5:1, and 1.9:1 in a light look.
  • danger and info on background and surface: 4.5:1.
  • accent.onFill on accent.fill and on accent.fill.pressed: 4.5:1.
  • On the full player's floor, over black artwork and over white: text and text.muted 4.5:1, accent 3:1.

4.5:1 is a floor, not a target: words read best nearer 7:1. An app holds a theme to the rules before it applies it, and a look that fails isn't shown. songstress check runs the apps' own code and reports a failing look as THEME_CONTRAST or THEME_LUMINANCE, with the ratio it reaches.

What no theme reaches

The logo and the app's icon, Wrapped's stories and share cards, the pages a public link opens, the first run, and supporters' medals keep Songstress's own look. So do what the system draws (the splash screen, widgets, the watch and car screens, system menus and pickers) and pictures. The full player and a page's header over its artwork are themed like every other screen.

Themes came with API 0.1.3, so a manifest with one asks for "songstress": "^0.1.3". A token is never renamed and never changes its meaning; a new one comes with a new minor version.

On this page