CSS to Tailwind: How to Convert Common CSS Properties into Utility Classes
Quick Answer
- Convert each CSS declaration into one or more Tailwind utility classes.
- Prefer standard utilities such as
p-4,flexandrounded-lgwhen values match your theme. - Use arbitrary values such as
w-[350px]only when no suitable theme utility exists. - Check responsive states, hover styles and custom selectors separately instead of converting only the base CSS.
Converting CSS to Tailwind is not simply replacing property names with shorter class names. You must understand what each declaration does, find the closest utility and decide whether the original value belongs in your design system.
This guide shows how to translate common layout, spacing, typography, color, border and responsive CSS into readable Tailwind utility classes.
In This Guide
What Does Converting CSS to Tailwind Mean?
Traditional CSS usually groups several declarations inside a named selector:
.card {
display: flex;
gap: 16px;
padding: 24px;
background-color: #ffffff;
border-radius: 12px;
box-shadow: 0 8px 24px rgb(15 23 42 / 10%);
}
In Tailwind, the same styling is composed directly in the markup:
<div class="flex gap-4 rounded-xl bg-white p-6 shadow-lg">
...
</div>
The classes are single-purpose utilities. Together, they recreate the layout and appearance previously stored in the custom CSS selector.
Common CSS to Tailwind Class Mapping
| CSS declaration | Tailwind class | Purpose |
|---|---|---|
display: flex; |
flex |
Flexbox container |
flex-direction: column; |
flex-col |
Vertical flex layout |
align-items: center; |
items-center |
Cross-axis alignment |
justify-content: space-between; |
justify-between |
Distributes available space |
gap: 16px; |
gap-4 |
One-rem gap on the default scale |
padding: 24px; |
p-6 |
Padding on every side |
margin: 0 auto; |
mx-auto |
Horizontal auto margins |
width: 100%; |
w-full |
Full available width |
height: 48px; |
h-12 |
Three-rem height |
font-size: 18px; |
text-lg |
Large text size |
font-weight: 600; |
font-semibold |
Semibold weight |
text-align: center; |
text-center |
Centres inline content |
background: #fff; |
bg-white |
White background |
border-radius: 12px; |
rounded-xl |
Rounded corners |
overflow: hidden; |
overflow-hidden |
Clips overflowing content |
The exact match can change when a project uses customised theme variables. Always check the active Tailwind theme instead of assuming that every project uses default values.
How to Convert CSS to Tailwind Step by Step
Separate declarations by purpose
Group the original CSS into layout, spacing, sizing, typography, background, border, effects and interaction states. This makes the class list easier to build and review.
Find the closest standard utility
Map values to your project’s existing spacing, colour, typography and shadow scales. Prefer a standard utility when the visual difference is negligible.
Convert pseudo-classes into variants
Translate selectors such as :hover, :focus and :disabled into variants such as hover:, focus: and disabled:.
Convert media queries into responsive variants
Move mobile styles into the unprefixed utilities, then use prefixes such as sm:, md: or lg: for larger screens.
Compare the rendered result
Check the converted component at different viewport sizes and interaction states. A class list is only correct when the result still matches the intended interface.
Practical CSS to Tailwind Examples
1. Flexbox layout
.actions {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
}
Tailwind:
class="flex items-center justify-between gap-4"
2. Card styling
.card {
padding: 24px;
background-color: white;
border: 1px solid #e2e8f0;
border-radius: 12px;
box-shadow: 0 10px 15px -3px rgb(15 23 42 / 10%);
}
Tailwind:
class="rounded-xl border border-slate-200 bg-white p-6 shadow-lg"
3. Typography
.title {
font-size: 24px;
line-height: 32px;
font-weight: 700;
letter-spacing: -0.025em;
color: #0f172a;
}
Tailwind:
class="text-2xl font-bold tracking-tight text-slate-900"
4. Hover and focus states
.button {
background-color: #4f46e5;
color: white;
}
.button:hover {
background-color: #4338ca;
}
.button:focus-visible {
outline: 2px solid #818cf8;
outline-offset: 2px;
}
Tailwind:
class="bg-indigo-600 text-white hover:bg-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-400"
How to Convert CSS Media Queries to Tailwind
Tailwind uses a mobile-first approach. Base utilities apply to every screen size, while prefixed utilities apply from the selected breakpoint upwards.
.grid {
display: grid;
grid-template-columns: 1fr;
gap: 16px;
}
@media (min-width: 768px) {
.grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 24px;
}
}
Tailwind:
class="grid grid-cols-1 gap-4 md:grid-cols-3 md:gap-6"
Common conversion mistake
Do not prefix the mobile utility. Start with the mobile layout, then override it at larger breakpoints—for example, flex-col md:flex-row.
When to Use Arbitrary Tailwind Values
Arbitrary values preserve CSS that does not match an existing utility. Tailwind places the custom value inside square brackets.
| Original CSS | Arbitrary utility |
|---|---|
width: 350px; |
w-[350px] |
background: #316ff6; |
bg-[#316ff6] |
top: calc(100% + 8px); |
top-[calc(100%+8px)] |
grid-template-columns: 240px 1fr; |
grid-cols-[240px_1fr] |
Repeated arbitrary values are usually a sign that the value should become part of the project theme. Keep one-off utilities for genuinely unique design requirements.
How to Decode Existing Tailwind Classes
Conversion also works in reverse. When you inherit markup containing a long utility string, identify each class category before changing the component.
Paste the classes into CSSPeek’s free Tailwind Class Decoder to translate dense utility strings into readable groups.
mx-auto flex max-w-xl items-center gap-4
rounded-xl border border-slate-200
bg-white p-6 shadow-lg
md:p-8 dark:bg-slate-900
Layout: flex items-center
Sizing: mx-auto max-w-xl
Spacing: gap-4 p-6 md:p-8
Appearance: rounded-xl border bg-white shadow-lg
Dark mode: dark:bg-slate-900
Convert Computed Website Styles into Tailwind
Sometimes you do not have the original stylesheet. You only have a live component whose spacing, typography or layout you want to understand.
The CSSPeek Chrome extension reveals the computed CSS behind the element you select, including its selector, box model, typography, colours and display properties.
1. Select the element using CSSPeek.
2. Record the computed display, sizing and spacing values.
3. Map typography and colour values to your Tailwind theme.
4. Recreate the component with utility classes.
5. Compare both versions at matching viewport sizes.
Explore CSSPeek’s selector inspection and typography inspection features for faster component analysis.
When a Tailwind Class Converter Is Not Enough
Automatic tools are useful for simple declarations, but they cannot always understand the design intent or full stylesheet context.
| Converter handles well | Manual review required |
|---|---|
| Basic spacing and sizing | Project-specific theme values |
| Common flex and grid declarations | Complex selectors and inherited styles |
| Standard colours and borders | Responsive and container-query behaviour |
| Simple typography | Pseudo-elements, animations and unusual CSS functions |
Also check which Tailwind version a converter targets. A tool built around an older version may produce utilities or configuration advice that does not match the current project.
CSS-to-Tailwind Conversion Checklist
✓ Identify every CSS declaration that affects the component.
✓ Map values to the existing Tailwind theme before using arbitrary classes.
✓ Convert hover, focus, active and disabled states.
✓ Convert media queries using mobile-first responsive variants.
✓ Check dark-mode styles when the original component supports them.
✓ Compare the original and converted component visually.
✓ Extract repeated patterns into reusable components or theme tokens.
CSSPeek Tailwind Class Decoder
Turn dense Tailwind class strings into readable styling decisions.
Paste utility classes, understand what each one controls and separate layout, spacing, typography and responsive variants more quickly.
Decode Tailwind Classes →Common CSS-to-Tailwind Mistakes
- Using arbitrary values for every declaration instead of following the theme.
- Ignoring inherited font, colour and line-height values.
- Converting desktop CSS first instead of preserving mobile-first behaviour.
- Forgetting hover, focus, active and disabled selectors.
- Assuming a similar utility is an exact visual match without testing it.
- Keeping repeated class strings in many files instead of creating a reusable component.
- Using an outdated converter without checking its supported Tailwind version.
Frequently Asked Questions
How do I convert CSS to Tailwind?
Break the CSS into individual declarations, map each value to the closest utility and convert states and media queries into Tailwind variants.
Can CSS be converted to Tailwind automatically?
Basic declarations can be converted automatically, but custom themes, inherited styles, complex selectors and responsive behaviour still require manual review.
How do I decode Tailwind classes?
Separate the utilities into layout, sizing, spacing, typography, colour, state and responsive groups, or use a Tailwind class decoder to explain them.
What are arbitrary values in Tailwind?
Arbitrary values use square brackets to apply a custom value that is not available in the theme, such as w-[350px] or bg-[#316ff6].
Should I replace all custom CSS with Tailwind classes?
No. Use utilities for common styling and keep custom CSS when it communicates complex behaviour more clearly or avoids an unreadable class list.