Theming
Staticview components read their styles from --sv-* CSS custom properties, the tokens. Define them once on :root, or override the color and size tokens on a container to theme one part of the page.
Without a theme, components stay usable with the browser's system colors, like AccentColor and ButtonBorder, and a theme gives them your palette.
Default Theme
The default theme supports light and dark mode, and you import it yourself:
@import "@staticview/ui/themes/default.css";Light & Dark Mode
Since the default theme picks its colors with light-dark(), which follows the page's color-scheme, declare a color scheme in your stylesheet, or every token resolves to its light value:
:root { /* Follow the user's OS or browser preference */ color-scheme: light dark;}Use color-scheme: light or color-scheme: dark to force one mode, on the page or on one section of it.
Changing the Hue
The default theme derives its grayscale and accent color from two hue tokens, and overriding them re-tints the whole theme:
:root { --sv-hue-accent: 260; /* OKLCH hue of the accent color, 0–360 */ --sv-hue-base: 240; /* OKLCH hue of the grayscale tint */}Set the hue tokens on :root, since a hue set on a container has no effect. To re-tint one part of the page, override the color tokens themselves, as Scoped Themes shows.
Token Reference
--sv-gray-0…--sv-gray-7: the grayscale ramp, from0, the highest-contrast color for text and icons, to7, the base surface color. The default theme flips the ramp between light and dark mode.--sv-accent: the brand color of primary actions and highlights.--sv-accent-content: the color of text and icons on the accent color.--sv-info,--sv-success,--sv-warning,--sv-error: the status colors of badges, callouts, toasts, and error and success states.--sv-overlay: the translucent backdrop behind dialogs.--sv-bdr-sz-sm/md/lg: border widths.--sv-bdr-rad-sm/md/lg: border radii.
The full default theme:
:root { /* Hue */ --sv-hue-accent: 85; --sv-hue-base: 305;
/* Grayscale */ --sv-gray-0: light-dark(oklch(30% 0.034 var(--sv-hue-base)), oklch(90% 0.017 var(--sv-hue-base))); --sv-gray-1: light-dark(oklch(33% 0.036 var(--sv-hue-base)), oklch(85% 0.024 var(--sv-hue-base))); --sv-gray-2: light-dark(oklch(36% 0.038 var(--sv-hue-base)), oklch(80% 0.03 var(--sv-hue-base))); --sv-gray-3: light-dark(oklch(44% 0.034 var(--sv-hue-base)), oklch(65% 0.028 var(--sv-hue-base))); --sv-gray-4: light-dark(oklch(66% 0.03 var(--sv-hue-base)), oklch(48% 0.024 var(--sv-hue-base))); --sv-gray-5: light-dark(oklch(88% 0.023 var(--sv-hue-base)), oklch(29% 0.02 var(--sv-hue-base))); --sv-gray-6: light-dark(oklch(93% 0.017 var(--sv-hue-base)), oklch(23% 0.017 var(--sv-hue-base))); --sv-gray-7: light-dark(oklch(96% 0.012 var(--sv-hue-base)), oklch(20.5% 0.014 var(--sv-hue-base)));
/* --- Main Brand Colors --- */ --sv-accent: light-dark(oklch(53% 0.108 var(--sv-hue-accent)), oklch(63% 0.105 var(--sv-hue-accent))); --sv-accent-content: var(--sv-gray-7);
/* --- Forced Colors --- */ @media (forced-colors: active) { --sv-gray-0: CanvasText; --sv-gray-1: CanvasText; --sv-gray-2: CanvasText; --sv-gray-3: CanvasText; --sv-gray-4: CanvasText; --sv-accent: Highlight; --sv-accent-content: HighlightText; }
/* --- Status/Semantic Colors --- */ --sv-info: light-dark(oklch(49% 0.17 262deg), oklch(78% 0.11 262deg)); --sv-success: light-dark(oklch(48% 0.115 155deg), oklch(80% 0.13 155deg)); --sv-warning: light-dark(oklch(50% 0.105 65deg), oklch(84% 0.12 80deg)); --sv-error: light-dark(oklch(50% 0.18 25deg), oklch(76% 0.13 22deg));
/* --- Overlay/Backdrop Color --- */ --sv-overlay: #000000a0;
/* --- Size Variables (Borders & Radius) --- */ --sv-bdr-sz-sm: 1px; --sv-bdr-sz-md: 2px; --sv-bdr-sz-lg: 4px; --sv-bdr-rad-sm: 4px; --sv-bdr-rad-md: 8px; --sv-bdr-rad-lg: 16px;}Custom Theme
Override Specific Tokens
Import the default theme and override only what you need:
@import "@staticview/ui/themes/default.css";
:root { --sv-accent: light-dark(#4c5fa8, #7c8fd1); --sv-bdr-rad-md: 12px;}Build a Theme from Scratch
Skip the default import and define the tokens in your stylesheet:
:root { --sv-gray-0: #f5f5f5; --sv-gray-1: #d4d4d4; --sv-gray-2: #a3a3a3; --sv-gray-3: #737373; --sv-gray-4: #525252; --sv-gray-5: #404040; --sv-gray-6: #262626; --sv-gray-7: #171717; --sv-accent: #7c8fd1; --sv-accent-content: #0f1117; --sv-info: #7fb8db; --sv-success: #8ec97f; --sv-warning: #f5d76e; --sv-error: #e87d7a; --sv-overlay: #000000a0; --sv-bdr-sz-sm: 1px; --sv-bdr-sz-md: 2px; --sv-bdr-sz-lg: 4px; --sv-bdr-rad-sm: 4px; --sv-bdr-rad-md: 8px; --sv-bdr-rad-lg: 16px;}Define every color token, since one you leave out falls back to the browser's system colors. Plain colors like the ones above give a theme with one mode, and wrapping each pair in light-dark(), as the default theme does, supports both modes.
Map to an Existing Design System
If your project already has design tokens, map them to the Staticview tokens instead of duplicating values:
@import "@staticview/ui/themes/default.css";
:root { --sv-gray-0: var(--sb-color-gray-0); --sv-gray-1: var(--sb-color-gray-1); --sv-gray-2: var(--sb-color-gray-2); --sv-gray-3: var(--sb-color-gray-3); --sv-gray-4: var(--sb-color-gray-4); --sv-gray-5: var(--sb-color-gray-5); --sv-gray-6: var(--sb-color-gray-6); --sv-gray-7: var(--sb-color-gray-7); --sv-accent: var(--sb-color-accent); --sv-info: var(--sb-note-text); --sv-success: var(--sb-tip-text); --sv-warning: var(--sb-warning-text); --sv-error: var(--sb-caution-text);}With the default import, sizes, radii, and any color you don't map keep their default values.
Scoped Themes
To re-theme one area, like a panel with different branding, override the tokens on its element:
.marketing-panel { --sv-accent: oklch(60% 0.15 300); --sv-bdr-rad-md: 16px;}RTL Support
Components follow the dir of their closest ancestor, and a theme needs no direction token.