Theming

How it works

ColorSnap UI themes are powered by CSS custom properties. Each built-in theme sets a consistent set of tokens on the document root. Components read these tokens at runtime, so switching themes updates every component instantly.

CSS Tokens

TokenDefaultDescription
--cs-bg#ffffffPage background
--cs-bg-subtle#f9f9f9Subtle background
--cs-fg#0a0a0aPrimary text
--cs-fg-muted#6b7280Muted text
--cs-border#e5e7ebBorder color
--cs-primary#2563ebPrimary accent
--cs-primary-fg#ffffffText on primary
--cs-danger#dc2626Danger/error
--cs-success#16a34aSuccess
--cs-warning#d97706Warning
--cs-radius5pxBorder radius

Themes

Theme Switcher

setTheme()

window.ColorSnap.setTheme('ocean');

initTheme()

window.ColorSnap.initTheme();

Call initTheme() on page load to restore the user's saved theme from localStorage.

Custom Themes

Override tokens on :root after loading ColorSnap to create a custom theme:

:root {
  --cs-primary: #7c3aed;
  --cs-bg: #fafafa;
  --cs-fg: #111111;
}

Custom overrides work with both npm and CDN usage.