DevDeck

CSS to Tailwind Converter โ€” Convert CSS Properties to Tailwind Classes

Migrating a project from plain CSS to Tailwind CSS or converting a CSS snippet for use in a React component? DevDeck's CSS โ†’ Tailwind Converter parses your CSS rules and maps each property to the equivalent Tailwind utility class โ€” with smart color handling, spacing scale conversion, and unmapped property annotations.

What is the CSS โ†’ Tailwind Converter?

It's a browser-based tool that takes standard CSS input and outputs equivalent Tailwind utility classes. It handles 120+ CSS properties across layout, typography, colors, spacing, borders, shadows, flexbox, grid, transforms, transitions, and more. Properties that have no direct Tailwind equivalent are annotated as comments so you know exactly what needs manual attention.

Why Convert CSS to Tailwind?

Tailwind's utility-first approach speeds up development by reducing context-switching between HTML and CSS files. Converting existing CSS to Tailwind lets you adopt this workflow incrementally โ€” migrate one component at a time without rewriting everything from scratch. The converter also helps when you're prototyping with CSS and want to translate your work into clean Tailwind classes.

Key Features

  • Parses multi-rule CSS with selectors and inline declarations
  • Maps 120+ CSS properties to Tailwind equivalents
  • Colors: hex, rgba, and named colors โ†’ Tailwind named classes or JIT arbitrary syntax
  • Spacing: px values mapped to the Tailwind spacing scale (p-4, m-10, etc.)
  • Unmapped properties shown as comments โ€” nothing is silently dropped
  • Stats badge shows 'X / Y properties mapped' for progress
  • 'Copy Classes' for clean class names, 'Copy All' to include annotations
  • 100% client-side โ€” no data leaves your browser

How Mapping Works

The converter uses a curated mapping table of ~120 CSS properties. Each property has a mapper function that receives the CSS value and returns one or more Tailwind class names. For example, display: flex โ†’ flex, justify-content: center โ†’ justify-center, padding: 8px 16px โ†’ px-4 py-8. Values that don't fit the Tailwind scale (like custom pixel values) use Tailwind's JIT arbitrary value syntax: w-[18px], text-[#ff6600].

Color Handling

Colors are handled specially. The converter recognizes named colors (white, black, red, blueโ€ฆ), hex codes (#fff, #000000, #22cc99โ€ฆ), and RGB/RGBA values. Common hex colors are mapped to their closest Tailwind named class: #fff โ†’ text-white, #22cc99 โ†’ bg-emerald-400, #3b82f6 โ†’ text-blue-500. For unrecognized colors or exact shades, the tool falls back to Tailwind's arbitrary value JIT syntax: text-[#ff6600] or bg-[rgba(34,51,68,0.5)].

Spacing Scale Conversion

Tailwind uses a predefined spacing scale (0.5, 1, 2, 4, 8, 16, 20, 24โ€ฆ rem-based units). The converter maps your px values to the closest scale match: 4px โ†’ 1 (p-1), 8px โ†’ 2 (m-2), 16px โ†’ 4 (gap-4). Values that don't have an exact match in the scale fall back to arbitrary value syntax: w-[18px].

CSS Shorthand Support

The converter handles CSS shorthand properties intelligently. margin: 10px becomes m-10, but margin: 10px 20px expands to my-10 mx-20, and margin: 10px 20px 30px 40px becomes mt-10 mr-20 mb-30 ml-40. If values repeat, the output is deduplicated โ€” margin: 10px 20px 10px 20px collapses to my-10 mx-20. The same logic applies to padding.

How to Use the CSS โ†’ Tailwind Converter

  1. Paste your CSS into the left panel (full rule blocks or just property: value pairs)
  2. The converter processes input in real-time with a 300ms debounce
  3. View the Tailwind class names in the right panel
  4. Check the stats badge for the mapped/total property count
  5. Review unmapped properties listed below the output
  6. Click 'Copy Classes' to copy clean class names for your className attribute
  7. Click 'Copy All' to copy classes plus unmapped annotations for review

Example Use Case

You're migrating a legacy Bootstrap project to Tailwind. You copy a CSS block like .btn { display: inline-flex; align-items: center; padding: 8px 16px; border-radius: 6px; font-weight: 700; } and paste it. The converter returns inline-flex items-center px-4 py-2 rounded-md font-bold โ€” ready to drop directly into your JSX className. The unmapped section shows any properties that need manual Tailwind equivalents.

Tips

  • Paste full CSS rule blocks with selectors โ€” the parser extracts properties correctly
  • Use 'Copy Classes' for clean output that goes straight into className attributes
  • For custom pixel values not in the Tailwind scale, use arbitrary value syntax like w-[22px]
  • The unmapped comments section helps you identify which properties need manual Tailwind equivalents like custom animations or specific box-shadow values
  • Combine with the Smart Formatter to detect and format CSS pasted from other sources

Ready to try it?

Related Tools

Color Converter

Color codes come in multiple formats depending on the context โ€” CSS uses HEX or โ€ฆ

JSON Viewer & Formatter

Raw JSON from APIs is often a single unreadable line. JSON Viewer formats it insโ€ฆ

YAML to JSON Converter

YAML is the language of configuration files โ€” Kubernetes, Docker Compose, GitHubโ€ฆ

Frequently Asked Questions

Yes, completely free with no signup required.

No. All conversion happens locally in your browser. Nothing is sent to any server.

Over 120 properties covering display, flexbox, grid, positioning, sizing, typography, colors, backgrounds, borders, shadows, opacity, transforms, transitions, and more.

They are shown as comments below the output (e.g., /* gap: 12px โ€” no Tailwind class */) so you know exactly what needs manual attention.

Not yet. The current version converts base CSS properties. Responsive variants (sm:, md:, lg:) and pseudo-classes (:hover, :focus) are on the roadmap.

Common hex colors are mapped to Tailwind named classes (#fff โ†’ white, #22cc99 โ†’ emerald-400). Unrecognized hex values use Tailwind's JIT arbitrary value syntax (text-[#ff6600]).

Yes. Shorthand values are expanded to the correct Tailwind directional classes (margin: 10px 20px โ†’ my-10 mx-20). Duplicate values are collapsed automatically.

DevDeck ยฉ 2023 - 2026

100% client-side โ€ข No data leaves your browser
CSS to Tailwind Converter โ€” Convert CSS Properties to Tailwind Classes | DevDeck