v3.2.1 — Now with twsx() variants

Tailwind Classes
to CSS Objects

Convert utility classes like flex items-center p-4 bg-blue-500 into real CSS — at runtime, build time, or anywhere JavaScript runs.

0 Dependencies
500+ Utilities
~38KB Gzipped
example.js
import { tws } from 'tailwind-to-style';

const styles = tws('flex items-center gap-4 p-6 rounded-xl bg-white/10 shadow-lg');

// Result:
// {
//   display: "flex",
//   alignItems: "center",
//   gap: "1rem",
//   padding: "1.5rem",
//   borderRadius: "0.75rem",
//   backgroundColor: "rgba(255,255,255,0.1)",
//   boxShadow: "0 10px 15px -3px rgba(0,0,0,0.1), ..."
// }

Built for Real-World Use

Not a Tailwind replacement — a bridge between Tailwind's class syntax and CSS-in-JS, native, or anywhere you need style objects.

Zero Dependencies

No PostCSS, no Tailwind CLI, no build tools. Pure JavaScript that works everywhere.

Runtime Ready

Use in the browser via CDN, in Node.js, or bundled. No compilation step required.

🧩

twsx() Variants

Component-style API with nested selectors, hover states, and media queries built in.

🎨

500+ Utilities

Layout, typography, colors, shadows, transforms, animations — the full Tailwind palette.

💉

Auto Inject CSS

twsx() can auto-inject generated CSS into a <style> tag. One call, styles applied.

📱

React Native

Output style objects that map directly to React Native's StyleSheet.create().

📐

Responsive

sm:, md:, lg:, xl: breakpoint prefixes — same as Tailwind, converted to @media rules.

🔄

States & Pseudo

hover:, focus:, active:, disabled:, first-child:, and more — all just work.

🎯

@css Escape Hatch

Need raw CSS? Use @css directive for anything Tailwind classes can't express.

This Page Uses twsx()

Every element below is styled with Tailwind classes via twsx(). Inspect the source — it's all tws('flex items-center ...').

Buttons

tws('px-5 py-2.5 rounded-lg font-semibold text-sm transition-all duration-200 hover:shadow-lg active:scale-95')

Card Component

JD
Jane Doe
Senior Engineer
PRO
tws('flex items-center gap-3 p-4 rounded-xl bg-white/5 border border-white/10')

Alerts

Changes saved successfully
Check your connection
Something went wrong
tws('flex items-center gap-2 px-4 py-2.5 rounded-lg text-sm font-medium')

Form Inputs

tws('w-full px-4 py-3 rounded-lg bg-white/5 border border-white/10 text-white text-sm')

Three Functions, Infinite Possibilities

tws(classes) Core

Convert a Tailwind class string into a CSS style object. Supports all standard utilities.

tws('p-4 flex gap-2 text-white')
// → { padding: "1rem", display: "flex", gap: "0.5rem", color: "#fff" }
twsx(map, options) Extended

Generate full CSS from a selector → classes map. Supports nesting, pseudo-classes, and @media.

twsx({
  '.btn': 'px-4 py-2 rounded-lg font-bold',
  '.btn:hover': 'bg-white/20 -translate-y-0.5'
})
twsx(map, { autoInjectCss }) Auto

Pass autoInjectCss: true and the generated CSS is immediately injected into a <style> tag.

twsx({
  '.card': 'p-6 rounded-xl shadow-lg bg-white/10'
}, { autoInjectCss: true })
@css { ... } Escape

Need something Tailwind can't express? Mix raw CSS alongside Tailwind classes using @css.

twsx({
  '.hero': [
    'text-center py-20',
    { '&': '@css { background: linear-gradient(...) }' }
  ]
})

Ready to Convert?

Install in seconds. No config. No build step. Just works.

npm install tailwind-to-style