CSS to Tailwind Converter
Convert CSS declarations to Tailwind CSS utility classes — supports margin, padding, flex, grid, typography, colors, and arbitrary value fallbacks.
Last updated: March 25, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is CSS to Tailwind Converter?
Tailwind CSS is a utility-first CSS framework that replaces traditional CSS rule sets with composable single-purpose classes applied directly in HTML: `class="flex items-center justify-between p-4 bg-white rounded-lg"`. While Tailwind is faster to write for new greenfield projects, migrating an existing CSS codebase means manually looking up which Tailwind class corresponds to each declaration — a slow, error-prone process.
This converter automates that lookup: paste any CSS declaration block and receive the equivalent Tailwind class string. The converter handles the most common CSS properties — display, flexbox (flex, align-items, justify-content), grid, margin, padding, width, height, font-size, font-weight, text-align, border, border-radius, background-color, color, position, overflow, opacity, cursor, and z-index. Values that map directly to Tailwind's default scale produce named classes (e.g., `p-4` for `padding: 1rem`). Values that don't match the Tailwind scale produce arbitrary value classes (e.g., `w-[130px]`) using Tailwind v3+'s JIT arbitrary value syntax.
How to Use CSS to Tailwind Converter
Paste a CSS rule block into the left panel — include the declarations but not necessarily the selector (e.g., just `display: flex; align-items: center;`)
Click "Convert" to generate the equivalent Tailwind class string
Review the output: matched classes show in blue, arbitrary-value classes show in yellow, and unsupported properties appear as HTML comments for manual handling
Copy the class string and apply it to your HTML element's `class` attribute
For full rule sets with selectors, each selector's declarations are converted separately — paste one selector at a time for clearest output
Common Use Cases
- Migrating a legacy CSS stylesheet to Tailwind during a frontend framework upgrade
- Learning which Tailwind class corresponds to a specific CSS property while transitioning from traditional CSS
- Converting a design token system (CSS custom properties with specific values) to Tailwind theme extensions
- Translating component styles from a CSS module file to Tailwind classes during a React component refactor
- Converting Bootstrap override CSS to Tailwind equivalents during a migration from Bootstrap to Tailwind
- Understanding Tailwind's spacing scale by seeing which CSS pixel values map to which Tailwind number codes
- Converting styles from a Figma CSS export (Figma's "Copy as CSS" feature) to Tailwind classes
- Generating Tailwind classes for a one-off element that needs specific styles outside your existing design system
Example Input and Output
Converting a CSS flexbox card component to Tailwind classes:
.card {
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 1.5rem;
background-color: #ffffff;
border-radius: 0.5rem;
border: 1px solid #e5e7eb;
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
max-width: 24rem;
}<!-- Tailwind classes -->
<div class="flex flex-col items-start p-6 bg-white rounded-lg border border-gray-200 shadow-sm max-w-sm">
Mapping breakdown:
display: flex → flex
flex-direction: column → flex-col
align-items: flex-start→ items-start
padding: 1.5rem → p-6
background-color:#fff → bg-white
border-radius: 0.5rem → rounded-lg
border: 1px solid ... → border border-gray-200
box-shadow: ... → shadow-sm
max-width: 24rem → max-w-smClient-Side Processing
All CSS parsing and Tailwind class mapping runs in your browser. Your CSS code is never sent to our servers.
Extending Tailwind for Off-Scale Values
If the converter frequently produces arbitrary values like w-[130px] or p-[7px], your design uses values outside Tailwind's default scale. Add your design tokens to tailwind.config.js: extend: { spacing: { 13: "3.25rem", 18: "4.5rem" } }. This makes them available as w-13, p-18 etc. and removes the need for arbitrary value syntax. Run npx tailwindcss --init to create a config file if you don't have one.
Tailwind CSS IntelliSense for VS Code
Install the official Tailwind CSS IntelliSense extension (bradlc.vscode-tailwindcss) to get autocomplete, hover previews, and linting for Tailwind classes in VS Code. As you apply converted classes to your HTML, IntelliSense shows what CSS each class generates on hover — making it easy to verify the conversion was correct without leaving your editor. The extension also warns when you use conflicting classes (e.g., both p-4 and px-2).
Frequently Asked Questions
What Tailwind version does this converter target?
What happens when a CSS value doesn't match Tailwind's default scale?
How does the converter handle CSS shorthand properties?
What CSS properties are not supported?
How do I handle hover, focus, and responsive styles?
Should I convert everything to Tailwind or keep some custom CSS?
How This Tool Works
CSS input is tokenized into property-value pairs using a CSS declaration parser. Each property is matched against a lookup table mapping CSS property + value patterns to Tailwind class names. Spacing values are normalized to rem and matched against Tailwind's spacing scale (multiples of 0.25rem). For color values, hex colors are compared against Tailwind's default palette; exact matches produce named classes (bg-gray-200), unrecognized hex colors produce arbitrary value classes (bg-[#custom]). Unrecognized properties are emitted as /* unmapped: property: value */ comments.
Technical Stack