Pixxl styles come from CSS custom properties (--pixxl-*). Components never hard-code colors, sizes or motion, so a site changes its look by setting a few variables or data attributes. This page covers the color system, typography, accent presets, a custom accent, dark mode, cascade layers and density.
Every token is defined in TypeScript (components/src/tokens) and generated into tokens.css.
Import @pixxl-tools/components/styles.css once, or only @pixxl-tools/components/tokens.css when you want the variables without component styles. The same values are exported as objects from @pixxl-tools/components/tokens for canvas renderers and charts (getThemeColors(theme, accent)).
Color roles are semantic: use --pixxl-color-text-muted for secondary text instead of picking a gray. Each text role is checked for WCAG AA contrast against every surface in both themes and for every accent preset (pnpm check:contrast).
--pixxl-color-background
Page background
--pixxl-color-surface
Cards, fields, menus
--pixxl-color-text
Body text
--pixxl-color-text-muted
Secondary text (AA on every surface)
--pixxl-color-border
Dividers and card borders
--pixxl-color-border-control
Field borders (3:1 against the surface)
--pixxl-color-accent
Primary fills, from the accent
--pixxl-color-accent-text
Links and accent text
--pixxl-color-focus
Focus outline
--pixxl-color-danger
Destructive actions
Inter, loaded by your site; the system UI font is the fallback.
Pixxl bundles no font files. --pixxl-font-family-sans is var(--pixxl-font-sans-brand, "Inter Variable"), "Inter Variable", Inter, system-ui, …: load Inter in your app and point --pixxl-font-sans-brand at it, or set the variable to your own brand stack. The type ramp (body 15/24, UI 14/20, labels 13/18 at weight 500, headings at 600 with negative tracking) and the OpenType features (--pixxl-font-feature-settings: single-storey a, open digits, round quotes) are tuned for Inter.
Next.js: use next/font/google, which self-hosts the files and adds a size-matched fallback font, so text does not shift when Inter arrives. Vite and other bundlers: install @fontsource-variable/inter and import it once; its family name, Inter Variable, is already in the stack. Polish and other Central European languages need the latin-ext subset.
Tables, stats, pagination, badges and other numbers that line up use font-variant-numeric: tabular-nums. Use --pixxl-font-mono-brand the same way for a custom monospace font.
// app/layout.tsx (Next.js)
import { Inter } from "next/font/google";
const inter = Inter({
display: "swap",
subsets: ["latin", "latin-ext"],
variable: "--font-inter",
});
export default function RootLayout({ children }) {
return (
<html className={inter.variable} lang="en">
<body>{children}</body>
</html>
);
}
/* app/globals.css */
:root {
--pixxl-font-sans-brand: var(--font-inter);
}Typography: app/layout.tsx// main.tsx (Vite): pnpm add @fontsource-variable/inter
import "@fontsource-variable/inter";
import "@pixxl-tools/components/styles.css";
/* Nothing else to set: "Inter Variable" is in the default stack.
To use another family, point the brand variable at it: */
:root {
--pixxl-font-sans-brand: "Geist", "Inter Variable";
}One accent drives every primary color: fills, hover and active states, soft backgrounds, borders, accent text, focus rings and the text on top of fills.
Set data-accent on <html> (or any element, for one section) to one of the presets, or pass accent to PixxlProvider or SitePreferencesProvider. Presets are tuned per theme so text stays readable.
There are ten presets: blue, violet, pink, orange, amber, green, teal, sky, rose and neutral. Amber is a deep gold in the light theme (white text on a fill needs a darker yellow than sRGB can keep saturated) and a bright amber with dark text in the dark theme; sky sits between teal and blue and also switches to dark text in the dark theme.
data-accent="blue"
data-accent="violet"
data-accent="pink"
data-accent="orange"
data-accent="amber"
data-accent="green"
data-accent="teal"
data-accent="sky"
data-accent="rose"
data-accent="neutral"
<html lang="en" data-accent="teal">…</html>
// or per provider:
<PixxlProvider accent="teal">…</PixxlProvider>
<SitePreferencesProvider accent="teal">…</SitePreferencesProvider>Accent presets: app/layout.tsxBrand colors that are not a preset.
The safest way to use a brand color is to set the accent hue and chroma. Lightness stays tuned per theme, so accent text, focus rings and the text on filled buttons keep their contrast. Drag the sliders to try it.
Accent colors are derived on the root and on elements with data-theme, data-accent, data-density or the pixxl-ui class, so set the variables on one of those (for one section: <section data-accent="brand" style="--pixxl-accent-hue: 25">).
To use one exact color for fills, set --pixxl-accent as well. Browsers with CSS relative colors (Chrome and Edge 119+, Safari 16.4+, Firefox 128+) derive accent text, the focus ring and the text on fills from it. Older browsers derive those from the hue, chroma and lightness variables, so keep --pixxl-accent-hue / --pixxl-accent-chroma close to your color and set --pixxl-accent-lightness-light and --pixxl-accent-lightness-dark to its oklch lightness. Check the result in both themes.
Hue 25
Chroma 0.19
/* Brand hue: contrast stays tuned per theme. */
:root {
--pixxl-accent-hue: 25;
--pixxl-accent-chroma: 0.19;
}
/* One exact fill color: also give its hue, chroma and lightness
(used where relative colors are not supported). */
:root {
--pixxl-accent: oklch(0.58 0.2 25);
--pixxl-accent-hue: 25;
--pixxl-accent-chroma: 0.2;
--pixxl-accent-lightness-light: 0.58;
--pixxl-accent-lightness-dark: 0.62;
}Custom accent: app.cssLight, dark or system, applied before the first paint.
Pixxl reads data-theme (light, dark or system) from the nearest ancestor. Without the attribute, or with system, it follows prefers-color-scheme live. Like the accent, the theme can be set on any element, which is how the previews below render both themes at once.
Render <ThemeScript /> in <head> so the stored choice is applied before React hydrates, and add suppressHydrationWarning to <html>. usePersistentTheme stores the choice in a cookie and localStorage; the cookie wins when both are set, so a choice made on another subdomain is not overridden by an older local value. cookieDomain={{ shared: ".example.com" }} shares it across subdomains and writes a host-only cookie anywhere else (localhost, preview hosts), and the server can read it with getThemeFromCookie(cookieHeader) to render the right data-theme directly. Use the same storageKey in the script and the hook.
Browser chrome: put getThemeColorMeta(accent) (from @pixxl-tools/components/tokens) in Next viewport.themeColor (or render the two <meta name="theme-color" media=…> tags). ThemeScript, SitePreferencesProvider and usePersistentTheme({ apply }) point the browser chrome at an explicit light or dark choice and back at the media entries for System. Hex values from getThemeColors are the colours browsers draw (out-of-gamut accents clipped per channel), so manifests and share images match the page.
SitePreferencesProvider does all of this for a whole site (theme, accent, density and locale), and ThemeSwitcher gives visitors the control.
Default storage keys and cookies. The theme is stored under pixxl-theme: the localStorage key and the cookie name (Path=/, SameSite=Lax, Secure, one year; cookieDomain adds Domain=). ThemeScript, getThemeScript(), usePersistentTheme, a standalone ThemeSwitcher, SitePreferencesProvider and getThemeFromCookie(cookieHeader) all use that one name by default, so nothing needs configuring. SitePreferencesProvider also keeps pixxl-accent and pixxl-density in localStorage and the locale in a pixxl-locale cookie (read it on the server with getLocaleFromCookie). Other built-in keys: analytics-consent (ConsentBanner), pixxl-install-prompt (InstallPrompt) and pixxl-package-manager (InstallCommand).
Keep the defaults, so every site and app on a domain shares the visitor’s choice. Change a key only when two apps on one origin must remember different choices, and then pass the same value everywhere: storageKey on ThemeScript, usePersistentTheme and ThemeSwitcher, or themeStorageKey (and themeCookieName if it differs) on SitePreferencesProvider, plus the cookieName argument of getThemeFromCookie. A mismatch shows as a flash of the wrong theme on load or a switcher that forgets the choice.
Moving from your own keys: migrateFrom on ThemeScript (or SitePreferencesProvider, which passes it on) moves a preference stored under an older key once, before first paint. For each entry the script reads the old value (localStorage, then a cookie of that name), passes it through map (values missing from the map are dropped), writes it as the new theme (localStorage and the theme cookie, on cookieDomain), accent or density unless a newer choice is already stored, and deletes the old item and cookie, so it never runs twice. The script and its CSP hash change when you add it; remove the option once visitors have moved over.
<SitePreferencesProvider
cookieDomain={{ shared: ".example.com" }}
migrateFrom={[
{ key: "theme", map: { dark: "dark", light: "light" } }, // "auto" is dropped
{ key: "site.tone", map: { grove: "teal", pulse: "violet" }, to: "accent" },
]}
>
{children}
</SitePreferencesProvider>Migrating stored keysdata-theme="light"
data-theme="dark"
import { ThemeScript } from "@pixxl-tools/components";
export default function RootLayout({ children }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
<ThemeScript storageKey="theme" />
</head>
<body>{children}</body>
</html>
);
}Dark mode: app/layout.tsx"use client";
import { ThemeSwitcher, usePersistentTheme } from "@pixxl-tools/components";
export function ThemeControl() {
const { theme, resolvedTheme, setTheme } = usePersistentTheme({
apply: true, // writes <html data-theme> (omit when a provider owns it)
cookieDomain: { shared: ".example.com" }, // every subdomain; host-only elsewhere
storageKey: "theme",
});
return (
<ThemeSwitcher
onValueChange={setTheme}
value={theme}
variant="segmented"
/>
);
// resolvedTheme is "light" or "dark" (system resolved)
}Single-page apps without a server render: put the output of getThemeScript({ storageKey }) in an inline script in index.html. With a strict CSP, allow it with a nonce or a hash.
How your CSS and Pixxl CSS combine.
All Pixxl CSS lives in four layers: pixxl.reset, pixxl.base, pixxl.components and pixxl.utilities. Styles outside any layer beat every layer, so a site overrides a component with a plain selector: no !important and no specificity fights.
The flip side: a global element reset outside a layer (* { padding: 0 }) also beats component styles. Put resets in pixxl.reset. When you use another layered framework, declare the combined order once, before importing anything.
/* Your overrides: unlayered, so they win. */
.pixxl-card {
border-radius: var(--pixxl-radius-xl);
}
.marketing .pixxl-button {
font-weight: var(--pixxl-font-weight-bold);
}
/* Your reset: inside Pixxl's reset layer. */
@layer pixxl.reset {
* {
margin: 0;
}
}Cascade layers: app.css/* With Tailwind v4 or any other layered CSS: one order for all. */
@layer pixxl.reset, theme, base, pixxl.base,
components, pixxl.components, utilities, pixxl.utilities;
@import "@pixxl-tools/components/styles.css";
@import "tailwindcss";Per-layer files are also published (@pixxl-tools/components/css/reset.css, base.css, components.css, utilities.css) if you want to skip one, for example the reset.
Comfortable for reading, compact for tools.
data-density="compact" (or density on PixxlProvider and SitePreferencesProvider) uses 15 px body text, 14 px interface text and smaller control heights. Coarse pointers always keep at least 44 px touch targets, and fields use 16 px text on small screens so iOS does not zoom.
data-density="comfortable"
Body text follows the density.
data-density="compact"
Body text follows the density.