API Reference
Complete API reference for typestyles
API Reference
Auto-generated documentation for all typestyles APIs.
Core Exports
styles
Default style API (semantic class names, empty scopeId). Prefer createStyles({ scopeId, mode, prefix })
per package or micro-frontend for isolation.
Methods:
styles.component(namespace, config): Create multi-variant component styles (CVA-style)styles.class(name, properties): Create a single classstyles.hashClass(properties, label?): Create a deterministic hashed classstyles.compose(...fns): Compose multiple style functionsstyles.withUtils(utils): Create utility-aware styles APIstyles.classNaming: Read-only resolved naming config for the defaultstylesinstance
createStyles(options?)
Returns a new style API (same shape as styles) with its own class naming config. Pass Partial<ClassNamingConfig>: mode ('semantic' | 'hashed' | 'atomic'), prefix, scopeId. Use one instance per package or micro-frontend.
The default import { styles } from 'typestyles' is createStyles() with default options.
tokens
Default token API (unscoped custom properties). Prefer createTokens({ scopeId }) when multiple
bundles share a page.
Methods:
tokens.create(namespace, values): Creates CSS custom propertiestokens.use(namespace): References existing tokenstokens.createTheme(name, config): Registers a theme class that overrides token custom propertiestokens.createDarkMode(name, darkOverrides): Shorthand theme with a single dark@mediabranchtokens.when/tokens.colorMode: Condition helpers for themestokens.scopeId: The scope passed tocreateTokens, if any
createTokens(options?)
Returns a token + theme API bound to an optional scopeId. When set, tokens.create('color', …) emits --{scopeId}-color-* variables and tokens.createTheme('dark', …) registers .theme-{scopeId}-dark (sanitized segments).
The default import { tokens } from 'typestyles' is createTokens() (no scope).
keyframes
Keyframe animation API.
Methods:
keyframes.create(name, stops): Creates @keyframes animation
color
Type-safe CSS color function helpers. Each function returns a plain CSS color string — no runtime color math. Composes naturally with token references.
Functions:
color.rgb(r, g, b, alpha?): RGB colorcolor.hsl(h, s, l, alpha?): HSL colorcolor.oklch(l, c, h, alpha?): OKLCH colorcolor.oklab(l, a, b, alpha?): OKLAB colorcolor.lab(l, a, b, alpha?): LAB colorcolor.lch(l, c, h, alpha?): LCH colorcolor.hwb(h, w, b, alpha?): HWB colorcolor.mix(c1, c2, p?, space?): Mix two colorscolor.lightDark(light, dark): Light/dark mode colorcolor.alpha(color, opacity, space?): Adjust opacity
See Color.
tokens.create(namespace, values): Registers tokens on:rootand returnsvar(--namespace-key)referencestokens.use(namespace): Returnsvar(--namespace-key)references without emitting CSS (for shared tokens defined elsewhere)tokens.createTheme(name, config): Registers a.theme-{name}surface with optionalbase, and eithermodesorcolorMode(not both). Returns aThemeSurface(className,name, string coercion)—use.classNamein Reacttokens.createDarkMode(name, darkOverrides): Shorthand for a single dark mode layer underprefers-color-scheme: darktokens.when: Condition builders (media,prefersDark,prefersLight,attr,className,selector,and,or,not) for manualmodestokens.colorMode: Presets (mediaOnly,attributeOnly,mediaOrAttribute,systemWithLightDarkOverride) that expand tomodes—pass ascolorModeoncreateTheme
global
Global CSS helpers (not scoped to a component class):
global.style(selector, styles): Insert rules for an arbitrary selectorglobal.fontFace(family, props): Register@font-face
cx(...parts)
Joins class name parts into a single string, filtering out falsy values (false, undefined, null, 0, '').
Use cx to combine TypeStyles classes with external class strings and conditional expressions.
import { cx, styles } from 'typestyles';
const card = styles.component('card', {
base: { padding: '16px' },
elevated: { boxShadow: '0 4px 12px rgba(0,0,0,0.1)' },
});
cx(card('base'), isElevated && card('elevated'), externalClassName);
CSS variables (advanced)
createVar(name, fallback?),assignVars(vars): Typed custom property helpers for advanced patterns
Sheet and testing utilities
getRegisteredCss(): Returns all CSS registered so far (useful with SSR or diagnostics)reset(),flushSync(),ensureDocumentStylesAttached(): Primarily for tests and advanced setup; see TestinginsertRules(rules): Low-level rule insertion (mainly for library authors)
Class naming helpers
mergeClassNaming(partial?): Build a fullClassNamingConfigfrom partial optionsdefaultClassNamingConfig: Defaultmode,prefix, andscopeIdscopedTokenNamespace(scopeId, logicalNamespace): CSS variable namespace segment for scoped token instances
See Class naming.
Usage Examples
Creating Styles
import { styles } from 'typestyles';
const button = styles.component('button', {
base: { padding: '8px 16px' },
variants: {
intent: { primary: { backgroundColor: '#0066ff' } },
},
defaultVariants: { intent: 'primary' },
});
button(); // "button-base button-intent-primary"
button({ intent: 'primary' }); // same
const { base } = button; // destructure class strings
Creating Tokens
import { tokens } from 'typestyles';
const color = tokens.create('color', {
primary: '#0066ff',
secondary: '#6b7280',
});
color.primary; // "var(--color-primary)"
Scoped instances (libraries / micro-frontends)
import { createStyles, createTokens } from 'typestyles';
export const styles = createStyles({ scopeId: 'my-ds', mode: 'hashed', prefix: 'ds' });
export const tokens = createTokens({ scopeId: 'my-ds' });
Creating Animations
import { keyframes } from 'typestyles';
const fadeIn = keyframes.create('fadeIn', {
from: { opacity: 0 },
to: { opacity: 1 },
});
// Use in styles
animation: `${fadeIn} 300ms ease`;
This API reference was auto-generated from source code. Last updated: 2026-04-04