🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

typestyles

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typestyles

CSS-in-TypeScript that embraces CSS instead of hiding from it

latest
Source
npmnpm
Version
0.9.0
Version published
Weekly downloads
2.6K
81.74%
Maintainers
1
Weekly downloads
 
Created
Source

typestyles

CSS-in-TypeScript that embraces CSS instead of hiding from it.

Write type-safe styles in TypeScript, get human-readable class names in DevTools, use CSS custom properties as first-class design tokens, and adopt incrementally alongside plain CSS. No build step required for the runtime path; optional bundler plugins extract static CSS for production.

Full documentation: typestyles.dev · Monorepo overview: README

For AI coding agents: read llms.txt in this package (API patterns, common mistakes, doc links) or query the live docs via MCP at typestyles.dev/mcp.

Install

npm install typestyles

Quick start

import { styles, tokens, cx } from 'typestyles';

const color = tokens.create('color', {
  primary: '#0066ff',
  surface: '#ffffff',
});

const button = styles.component('button', {
  base: {
    padding: '8px 16px',
    borderRadius: '6px',
    backgroundColor: color.primary,
    color: color.surface,
    '&:hover': { filter: 'brightness(0.9)' },
  },
  variants: {
    intent: {
      primary: { backgroundColor: color.primary },
      ghost: { backgroundColor: 'transparent', color: color.primary },
    },
  },
  defaultVariants: { intent: 'primary' },
});

// Callable + destructurable
<button className={button({ intent: 'ghost' })} />;
// → class="button-base button-intent-ghost"

Subpath exports

ImportUse for
typestylesstyles, tokens, cx, createStyles, createTokens, createVar, …
typestyles/servercollectStyles, getRegisteredCss, streaming SSR helpers
typestyles/buildBuild-time stubs when runtime is disabled
typestyles/hmrHMR invalidation (used by @typestyles/vite)
typestyles/colorColor helpers (rgb, oklch, mix, …) — kept off the main entry for bundle size
typestyles/globalsAmbient types for CSS modules and global augmentation

Runtime vs zero-runtime

ModeHow
Runtime (default)Styles inject into a managed <style> tag on first use (~15 KB gzip main entry; CI enforces a budget)
Zero-runtime (opt-in)@typestyles/vite, @typestyles/rollup, @typestyles/esbuild, @typestyles/webpack, or @typestyles/next/build extract a static .css file

Same authoring API in both modes.

SSR

import { collectStyles } from 'typestyles/server';

const { html, css } = await collectStyles(() => renderToString(<App />));
// Inject `css` into <head>

Request-safe collection uses AsyncLocalStorage on Node — see SSR guide.

Ecosystem packages

PackagePurpose
@typestyles/viteVite — HMR + extraction
@typestyles/nextNext.js App/Pages Router
@typestyles/propsTyped atomic utilities
@typestyles/open-propsOpen Props tokens
@typestyles/migrateCodemods from styled-components / Emotion
@typestyles/eslint-pluginESLint rules for style objects

See the packages index for bundler plugins and build tooling.

License

Apache-2.0

Keywords

css

FAQs

Package last updated on 10 Jul 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts