Skip to content
Sveltier
Mode
API

defineTheme

Builds a complete, contract-satisfying theme from a partial one.

Signature

Signature
import { defineTheme, type ThemeInput, type ThemeDefinition } from 'sveltier';

function defineTheme(input: ThemeInput, base: ThemeDefinition): ThemeDefinition;

Parameters

NameTypeDefaultDescription
input.darkbooleanbase.darkWhether the theme is dark.
input.colorsPartial<ThemeColors>โ€“Colours to override or add, as oklch() strings. Each overridden colour gets a fresh on- colour unless you pass one.
input.variablesPartial<ThemeVariables>โ€“Theme contract variables to override, plus any extra custom properties.
baseThemeDefinitionโ€“Required. The theme to extend, usually a pack theme such as monolithLight. It is never mutated.

Example

brand.ts
import { defineTheme } from 'sveltier';
import { monolithLight } from 'sveltier/themes/monolith';

// Extends Monolith light; everything you leave out comes from it.
export const brand = defineTheme({
  colors: {
    primary: 'oklch(0.52 0.16 255)',   // on-primary is computed for you
    brand: 'oklch(0.62 0.17 35)'        // custom colour: --sv-color-brand, --sv-on-brand
  },
  variables: {
    'radius-md': '13px',
    'font-display': "'Fraunces Variable', Georgia, serif"
  }
}, monolithLight);

Size

defineTheme() carries the colour maths that computes on- colours (under 1 KB gzipped). The built-in theme packs do not need it; they ship precomputed values.

More in Custom themes.