# tailwind-to-style > Zero-build runtime Tailwind CSS engine. Convert utility classes to real CSS at runtime — with variants, slots, design tokens, and React bindings. ## Installation ``` npm install tailwind-to-style ``` ## Overview tailwind-to-style replaces the Tailwind CSS build step entirely. You write Tailwind utility classes as strings, and the library generates and injects real CSS into the DOM at runtime. It supports responsive breakpoints (md:, lg:), pseudo-classes (hover:, focus:), arbitrary values, variants, slots, design tokens, and SSR. --- ## API Reference ### `tw()` — The main function (4 modes) #### Mode 1: Atomic classes Pass a string of Tailwind utilities. Returns auto-generated class names. CSS is injected into the DOM automatically, including @media queries and pseudo-class rules. ```js import { tw } from 'tailwind-to-style'; tw('flex items-center gap-4 hover:bg-gray-100 md:hidden') // Returns: "tw-flex tw-items-center tw-gap-4 tw-hover-bg-gray-100 tw-md-hidden" ``` Use with `className={}` in React. Supports all responsive prefixes (sm:, md:, lg:, xl:, 2xl:) and pseudo-classes (hover:, focus:, active:, disabled:, focus-within:, etc.). #### Mode 2: Named class (preferred for static styles) Two string arguments: name + Tailwind classes. Returns the name as the class. This is the preferred shorthand for defining reusable static styles. ```js tw('sidebar', 'w-64 h-screen bg-white border-r border-gray-200') // Returns: "sidebar" // Injects: .sidebar { width: 16rem; height: 100vh; background: #fff; ... } ``` #### Mode 3: Variants (returns a selector function) Object config with `name`, `base`, `variants`, optional `compoundVariants` and `defaultVariants`. Returns a function you call with variant selections. ```js const button = tw({ name: 'btn', base: 'px-4 py-2 rounded-lg font-medium transition-all cursor-pointer', variants: { color: { primary: 'bg-blue-600 text-white hover:bg-blue-700', secondary: 'bg-gray-200 text-gray-900 hover:bg-gray-300', danger: 'bg-red-600 text-white hover:bg-red-700', ghost: 'bg-transparent text-gray-700 hover:bg-gray-100', }, size: { sm: 'text-sm px-3 py-1.5', md: 'text-base px-4 py-2', lg: 'text-lg px-6 py-3', }, fullWidth: { true: 'w-full', }, }, compoundVariants: [ { color: 'primary', size: 'lg', class: 'shadow-lg shadow-blue-500/25' }, { color: 'danger', size: 'lg', class: 'shadow-lg shadow-red-500/25' }, ], defaultVariants: { color: 'primary', size: 'md' }, }) button({ color: 'danger', size: 'lg' }) // Returns: "btn btn--color-danger btn--size-lg" ``` #### Mode 4: Slots (multi-part components) Object config with `name`, `slots`, and `variants` where each variant value is an object mapping slot names to classes. ```js const card = tw({ name: 'card', slots: { root: 'bg-white rounded-xl border overflow-hidden', header: 'border-b flex items-center justify-between', title: 'font-semibold text-gray-900', body: 'text-gray-700', footer: 'border-t bg-gray-50', }, variants: { variant: { default: { root: 'border-gray-200 shadow-sm', header: 'border-gray-100', footer: 'border-gray-100', }, elevated: { root: 'border-gray-200 shadow-lg hover:shadow-xl', header: 'border-gray-100', footer: 'border-gray-100', }, }, size: { sm: { header: 'px-4 py-3', title: 'text-sm', body: 'px-4 py-3 text-sm', footer: 'px-4 py-3' }, md: { header: 'px-6 py-4', title: 'text-base', body: 'px-6 py-4', footer: 'px-6 py-4' }, lg: { header: 'px-8 py-5', title: 'text-lg', body: 'px-8 py-5', footer: 'px-8 py-5' }, }, }, defaultVariants: { variant: 'default', size: 'md' }, }) const slots = card({ variant: 'elevated', size: 'lg' }) // Returns: { root: "card__root card__root--variant-elevated card__root--size-lg", ... } // Use: