How to Convert CSS to Tailwind: A Practical Migration Guide
Migrating from vanilla CSS to Tailwind CSS is one of the most common transitions in modern frontend development. Instead of writing separate stylesheet files with custom class names, Tailwind lets you apply styles directly in your markup using utility classes. This guide covers the key property mappings you need to know, the Tailwind spacing scale, how to handle values that do not have a built-in utility, and practical migration strategies for real projects.
Why Migrate to Tailwind?
- No naming fatigue. You stop inventing class names like
.card-wrapper-innerand just describe what the element looks like. - Co-located styles. Styles live next to the markup, so you never have to switch between HTML and CSS files to understand a component.
- Consistent design tokens. Tailwind enforces a fixed spacing, color and typography scale, reducing visual inconsistency across a project.
- Smaller CSS bundles. Tailwind purges unused utilities at build time, often producing smaller CSS files than hand-written stylesheets that accumulate dead code.
- Responsive design built in. Breakpoint prefixes like
md:andlg:make responsive layouts trivial to implement.
Core Property Mappings
The most important step in converting CSS to Tailwind is knowing which utility class corresponds to each CSS property. Here are the most common mappings.
Display and Position
display: flex → flex
display: grid → grid
display: none → hidden
display: block → block
display: inline-flex → inline-flex
position: relative → relative
position: absolute → absolute
position: sticky → sticky
Flexbox
flex-direction: column → flex-col
align-items: center → items-center
justify-content: space-between → justify-between
justify-content: center → justify-center
flex-wrap: wrap → flex-wrap
flex: 1 1 0% → flex-1
flex-shrink: 0 → shrink-0
Spacing
Tailwind uses a spacing scale where each unit is 0.25rem. The pattern applies to padding, margin and gap:
padding: 1rem → p-4
padding: 1.5rem → p-6
margin-top: 2rem → mt-8
margin: auto → m-auto
margin-left: auto; margin-right: auto → mx-auto
gap: 1.5rem → gap-6
padding-left: 1rem; padding-right: 1rem → px-4
To convert a rem value to a Tailwind number, divide by 0.25. So 2rem is 2 / 0.25 = 8, giving you p-8.
Sizing
width: 100% → w-full
height: 100vh → h-screen
min-height: 100vh → min-h-screen
max-width: 80rem → max-w-7xl
max-width: 100% → max-w-full
Typography
font-size: 0.875rem → text-sm
font-size: 1.5rem → text-2xl
font-weight: 700 → font-bold
font-weight: 500 → font-medium
text-align: center → text-center
text-transform: uppercase → uppercase
line-height: 1.5 → leading-normal
Borders and Radius
border-width: 1px → border
border-radius: 0.5rem → rounded-lg
border-radius: 0.75rem → rounded-xl
border-radius: 9999px → rounded-full
border-style: dashed → border-dashed
Handling Arbitrary Values
Not every CSS value has a matching Tailwind utility. For custom values, Tailwind supports arbitrary value syntax using square brackets. This is one of the most useful features when migrating existing CSS:
width: 200px → w-[200px]
max-width: 1140px → max-w-[1140px]
margin-top: 13px → mt-[13px]
font-size: 15px → text-[15px]
background-color: #1a1a2e → bg-[#1a1a2e]
z-index: 999 → z-[999]
Arbitrary values are a migration escape hatch. Use them when needed, but prefer Tailwind's built-in scale values for consistency. Over time, you can replace arbitrary values with custom theme extensions in your Tailwind config.
A Full Conversion Example
Vanilla CSS:
.card {
display: flex;
flex-direction: column;
padding: 1.5rem;
gap: 1rem;
background-color: #ffffff;
border-radius: 0.75rem;
border-width: 1px;
border-color: #e5e7eb;
}
Tailwind:
Migration Tips
- Migrate component by component. Do not try to convert the entire codebase at once. Pick one component, convert it, test it, then move on.
- Use a converter tool first. Automated converters handle 80% of the work. Review the output and adjust the remaining 20% manually.
- Keep your CSS file as fallback. During migration, keep the original stylesheet in place and remove classes one by one as you replace them with Tailwind utilities.
- Extend your Tailwind config. If your design uses custom colors, spacing or breakpoints, add them to
tailwind.config.jsinstead of using arbitrary values everywhere. - Test responsive behavior. CSS media queries map to Tailwind breakpoint prefixes. Make sure you convert all breakpoints, not just the base styles.
Convert your CSS to Tailwind instantly
Paste vanilla CSS code and get the equivalent Tailwind utility classes in real time. Supports selectors, spacing, flexbox, grid, typography and colors.
Open CSS to Tailwind Converter