🌊 Tailwind ↔ CSS Converter
Convert plain CSS to Tailwind CSS utility classes instantly. Automatically maps colors, spacing, typography, and more. Free online CSS to Tailwind converter for developers.
How to Use
Choose direction
Select "Tailwind → CSS" to convert class names to CSS properties, or "CSS → Tailwind" to go the other way.
Paste your code
Type or paste Tailwind classes (space-separated) or CSS properties in the input area.
Copy the output
Click Convert and then Copy to use the result in your project.
Frequently Asked Questions
Complete Guide: CSS to Tailwind Converter
Tailwind CSS has become one of the most popular CSS frameworks in web development, shifting the paradigm from semantic class names to utility-first composition. Converting an existing CSS codebase — or translating hand-written CSS into Tailwind classes — is a common task when migrating projects or prototyping with a design system. This guide covers the utility-first philosophy, the most common CSS-to-Tailwind mappings, and the practical boundaries of what Tailwind handles well versus where plain CSS remains necessary.
The Utility-First Approach
Traditional CSS methodology encourages semantic class names: .card, .hero-button, .sidebar-nav. You write CSS rules that describe what these components look like. Tailwind inverts this: you apply small, single-purpose utility classes directly in your HTML, composing the final look from primitives like flex, p-4, text-lg, and bg-blue-500. The advantage is that you never write CSS directly for most UI work — the utility classes are the CSS. The trade-off is more verbose HTML markup.
Common CSS to Tailwind Mappings
Here are the most frequently converted CSS properties:
margin: 16px→m-4(Tailwind uses a 4px base unit, so 4 = 16px)padding: 8px 16px→py-2 px-4display: flex; align-items: center; justify-content: space-between→flex items-center justify-betweenfont-size: 1.25rem; font-weight: 600→text-xl font-semiboldcolor: #3b82f6→text-blue-500(if using default palette)border-radius: 8px→rounded-lgbox-shadow: 0 4px 6px -1px rgba(0,0,0,.1)→shadow-md
JIT Mode and Arbitrary Values
Tailwind's Just-In-Time (JIT) compiler generates only the classes you actually use, keeping your production CSS bundle small. JIT also enables arbitrary values — any CSS value can be expressed using bracket notation:
w-[337px] /* width: 337px */
text-[#1a2b3c] /* color: #1a2b3c */
mt-[clamp(1rem,5vw,3rem)] /* custom clamp() value */
grid-cols-[1fr_2fr_1fr] /* custom grid template */
Arbitrary values are a pragmatic escape hatch — use them when a design requires a specific value that doesn't fit Tailwind's default scale.
The @apply Directive
When the same combination of utility classes repeats across many elements, the @apply directive lets you extract them into a reusable CSS class:
.btn-primary {
@apply px-6 py-3 bg-blue-600 text-white font-semibold rounded-lg
hover:bg-blue-700 focus:outline-none focus:ring-2
focus:ring-blue-500 focus:ring-offset-2;
}
Use @apply sparingly — it reintroduces the abstraction layer that Tailwind's utility-first approach was designed to eliminate. The Tailwind team recommends using it only for third-party content you don't control or very high-frequency repeated patterns.
When NOT to Use Tailwind
Tailwind excels at layout, spacing, typography, and color. It struggles with:
- Complex animations: Keyframe animations with multiple steps require custom CSS or Tailwind plugins. The built-in animation utilities (
animate-spin,animate-bounce) cover only basics. - Complex pseudo-elements:
::beforeand::aftercontent cannot be set with utilities alone. - Highly dynamic styles: When class names must be fully constructed at runtime (e.g.,
'bg-' + color), Tailwind's JIT won't detect them in static analysis. Full class names must appear as strings.
Tailwind Config Customization
Extend Tailwind's default theme in tailwind.config.js without overriding built-in values:
module.exports = {
theme: {
extend: {
colors: {
brand: { 500: '#e63946', 600: '#c1121f' }
},
fontFamily: {
display: ['"Cal Sans"', 'sans-serif']
},
spacing: {
18: '4.5rem',
88: '22rem'
}
}
}
};
Migration Workflow: Existing CSS to Tailwind
- Audit your existing CSS to identify repeated patterns and component-level styles
- Convert layout and spacing rules first — these have the most direct Tailwind equivalents
- Convert typography and color rules, updating to your Tailwind palette as you go
- Handle edge cases with arbitrary values (
w-[337px]) rather than maintaining a parallel CSS file - Replace repeated utility combos with
@applyin component CSS as a final cleanup step
For generating glassmorphism effects that need custom backdrop-blur values, see CSS Glassmorphism. For gradient backgrounds that translate to Tailwind gradient utilities, use the Gradient Generator.