npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

transform-to-tailwindcss-core

v0.0.43

Published

🎨 A powerful, lightweight core library to transform CSS styles or style objects into Tailwind CSS utility classes. Perfect for migration projects and dynamic style generation.

Readme

🎨 Transform to Tailwind CSS Core

npm version License: MIT TypeScript Downloads

πŸš€ A powerful, lightweight core library to transform CSS styles or style objects into Tailwind CSS utility classes. Perfect for migration projects and dynamic style generation.

✨ Features

  • πŸ”„ Bidirectional Conversion: Transform CSS styles to Tailwind CSS classes
  • 🎯 Smart Parsing: Handles complex CSS properties and vendor prefixes
  • πŸ“± Responsive Support: Converts responsive CSS to Tailwind breakpoints
  • 🧩 TypeScript First: Full TypeScript support with type definitions
  • πŸͺΆ Lightweight: Zero dependencies, optimized for performance
  • 🌐 Browser Compatible: Works in both Node.js and browser environments
  • πŸ› Debug Mode: Built-in debugging for troubleshooting conversions
  • πŸ†• Tailwind v4 Mode: Optional canonical output for current Tailwind docs utility syntax

πŸ“¦ Installation

# npm
npm install transform-to-tailwindcss-core

# yarn
yarn add transform-to-tailwindcss-core

# pnpm
pnpm add transform-to-tailwindcss-core

πŸš€ Quick Start

import { toTailwindcss, transformStyleToTailwindcss } from 'transform-to-tailwindcss-core'

// Basic usage
const [tailwindClasses, unconverted] = transformStyleToTailwindcss(
  'color: red; font-size: 16px; margin: 10px'
)

console.log(tailwindClasses) // "text-[red] text-[16px] m-[10px]"
console.log(unconverted) // [] (empty if all styles converted)

// With rem units
const [classes, unconverted] = transformStyleToTailwindcss(
  'padding: 8px; background-color: #3b82f6',
  true // enable rem conversion
)

// With debug mode
const [classes, unconverted] = transformStyleToTailwindcss(
  'display: flex; justify-content: center',
  false, // rem conversion
  true // debug mode - shows conversion process
)

// Tailwind v4 canonical output
console.log(toTailwindcss('aspect-ratio: 1 / 1;', false, true)) // "aspect-square"
console.log(toTailwindcss('width: 100%;', false, true)) // "w-full"
console.log(toTailwindcss('rotate: 45deg;', false, true)) // "rotate-45"

πŸ“– API Reference

transformStyleToTailwindcss(styles, isRem?, debug?, isV4?)

Converts CSS styles to Tailwind CSS utility classes.

Parameters

  • styles (string): CSS styles to convert (e.g., "color: red; font-size: 16px")
  • isRem (boolean, optional): Whether to convert pixel values to rem units
  • debug (boolean, optional): Enable debug logging to see conversion process
  • isV4 (boolean, optional): Prefer Tailwind v4 canonical utility output for supported property pages

Returns

Returns a tuple [string, string[]]:

  • First element: Converted Tailwind CSS classes as a string
  • Second element: Array of unconverted CSS styles

toTailwindcss(css, isRem?, isV4?)

Converts a single CSS declaration to a Tailwind utility string.

Parameters

  • css (string): A single CSS declaration (e.g. "aspect-ratio: 1 / 1;")
  • isRem (boolean, optional): Whether to convert pixel values to rem units
  • isV4 (boolean, optional): Prefer Tailwind v4 canonical utility output for supported property pages

Examples

toTailwindcss('aspect-ratio: 1 / 1;') // "aspect-[1/1]"
toTailwindcss('aspect-ratio: 1 / 1;', false, true) // "aspect-square"

toTailwindcss('line-clamp: 3;', false, true) // "line-clamp-3"
toTailwindcss('color-scheme: light dark;', false, true) // "scheme-light-dark"

Tailwind v4 Mode

isV4 is opt-in so existing integrations keep the current output by default.

When isV4 is true, the converter prefers current Tailwind documentation syntax for supported utilities, for example:

toTailwindcss('aspect-ratio: var(--aspect-video);', false, true) // "aspect-video"
toTailwindcss('inline-size: 100%;', false, true) // "inline-full"
toTailwindcss('block-size: 100vh;', false, true) // "block-screen"
toTailwindcss('font-stretch: condensed;', false, true) // "font-stretch-condensed"
toTailwindcss('text-shadow: none;', false, true) // "text-shadow-none"
toTailwindcss('translate: 100% 100%;', false, true) // "translate-full"

🎯 Supported CSS Properties

This library supports a wide range of CSS properties including:

  • Layout: display, position, top, right, bottom, left
  • Flexbox: flex, flex-direction, justify-content, align-items
  • Grid: grid, grid-template-columns, grid-template-rows
  • Spacing: margin, padding, gap
  • Sizing: width, height, max-width, min-height
  • Typography: font-size, font-weight, text-align, line-height
  • Colors: color, background-color, border-color
  • Borders: border, border-width, border-radius
  • Effects: box-shadow, opacity, transform
  • And many more...

Tailwind v4 mode also covers current property-page syntax across the Tailwind docs categories such as Layout, Flexbox & Grid, Sizing, Typography, Backgrounds, Borders, Effects, Filters, Tables, Transitions & Animation, Transforms, Interactivity, SVG, and Accessibility.

πŸ”§ Advanced Usage

Debug Mode

Enable debug mode to see detailed conversion logs:

const [classes, unconverted] = transformStyleToTailwindcss(
  'color: #ff0000; font-size: 18px; margin-top: 20px',
  false,
  true // debug mode
)

// Console output:
// πŸ” [DEBUG] Input styles: color: #ff0000; font-size: 18px; margin-top: 20px
// πŸ” [DEBUG] Processing style: color: #ff0000 -> key: color: #ff0000
// πŸ” [DEBUG] Converted to Tailwind: color: #ff0000 -> text-red-500
// πŸ” [DEBUG] Processing style: font-size: 18px -> key: font-size: 18px
// πŸ” [DEBUG] Converted to Tailwind: font-size: 18px -> text-lg
// ...

Handling Unconverted Styles

const [classes, unconverted] = transformStyleToTailwindcss(
  'color: red; custom-property: value; font-size: 16px'
)

console.log(classes) // "text-red-500 text-base"
console.log(unconverted) // ["custom-property: value"]

// You can combine them for fallback
const finalStyles = unconverted.length > 0
  ? `${classes} [&]:${unconverted.join('; ')}`
  : classes

πŸ› οΈ Use Cases

  • Legacy Code Migration: Convert existing CSS to Tailwind CSS
  • Dynamic Styling: Generate Tailwind classes from user input
  • Design Tools: Build CSS-to-Tailwind converters
  • Component Libraries: Transform inline styles to utility classes
  • Development Tools: Create IDE extensions or build plugins

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

MIT License Β© 2022 Simon He

πŸ’– Support

If this project helped you, please consider:

sponsors