CSS to Tailwind Converter
Migrating a legacy CSS codebase to Tailwind is tedious. Every rule needs to be mentally translated from 'padding: 24px' to 'p-6', from 'display: flex' to 'flex', from 'border-radius: 12px' to 'rounded-xl'. This tool does the lookup for you. Paste one rule or a whole stylesheet and get the classes for each selector, ready to drop into your className attribute.
What It Maps
Full spacing scale — padding, margin, gap in pixels or rem, mapped to Tailwind's 4px-based scale when the value is exact (1=4px, 2=8px, 4=16px, 6=24px) and to arbitrary values otherwise. Typography — font-size, font-weight (100-900), line-height, text-align, text-transform, text-decoration, font-style. Flex & Grid — display, flex-direction, justify-content, align-items, flex-wrap, grid-template-columns. Position & Size — position, top/right/bottom/left, width, height, min/max dimensions. Borders — width, style, color, radius with shorthand parsing. Arbitrary fallback — any value without an exact class gets wrapped in brackets: p-[13px], bg-[#f5a623]; properties without a utility become [property:value].
See also: For full pre-built components rather than a single conversion, the Tailwind Component Builder assembles cards, navs, and form patterns.
Common Use Cases
Migrating an existing stylesheet to a Tailwind-based design system without manually matching every CSS rule against the utility classes. Reviewing a designer's CSS handoff and seeing which spacings, colors, and font sizes map to your Tailwind theme scale and which fall outside it — those are the ones that need a design-token conversation before they harden into the codebase.
Onboarding a new team to Tailwind by showing the equivalence between the CSS they already know and the utility classes they're about to learn. Auditing third-party widget styles before integrating them into a Tailwind project, so the embedded CSS doesn't fight your utility classes at runtime. Validating a Tailwind config change by converting key CSS rules and confirming the output uses the new theme values instead of arbitrary brackets.
Worked example: compiled by Tailwind and compared in Chromium
On October 12, 2026 we converted 9 rules (about 70 declarations, including a :hover rule, an @media rule, shorthands, colours, shadows, transitions and !important), compiled the output with Tailwind CSS 3.4.17 and compared every computed style in Chromium with the original CSS, at 1280 px, at 390 px and with :hover forced: 27 of 27 checks identical, transitions included. Until that day the tool used hand-made tables that wrote m-[8px 16px], gave font sizes an extra line height, turned red into red-500 and merged several rules into one broken class. Some results:
| Your CSS | Classes written |
|---|---|
margin: 0 auto | my-0 mx-auto |
margin: 8px 16px | mx-4 my-2 |
padding: 13px 7px 2px | pb-0.5 pt-[13px] px-[7px] |
font-size: 14px; line-height: 20px | text-sm (its built-in line height matches) |
font-size: 16px (no line-height) | text-[length:16px] (font size only) |
color: rgb(59, 130, 246) | text-blue-500 (exact palette colour) |
color: #333 | text-[#333] |
box-shadow: 0 2px 8px rgba(0,0,0,0.1) | shadow-[0_2px_8px_rgba(0,0,0,0.1)] |
transition: all 0.3s ease | [transition:all_0.3s_ease] |
.t5:hover { transform: translateY(-2px) } | hover:-translate-y-0.5 |
@media (min-width: 768px) | md: |
margin-top: 3px !important | !mt-[3px] |
- Exact first, arbitrary when needed. Every default Tailwind 3.4.17 class is indexed by the exact CSS it produces, from tables generated from Tailwind's own output. A declaration becomes a named class only when the values are identical; otherwise it becomes an arbitrary value with spaces written as underscores, or an arbitrary property such as [transition:…] when no utility fits. So text-sm is used only when your line height is 20px too, and red stays red rather than becoming red-500.
- Several rules, :hover and @media. Each selector gets its own class list. Pseudo-classes such as :hover, :focus and :first-child and pseudo-elements such as ::before become variants, and min-width media queries become sm: to 2xl: (or min-[…]: for other widths). Rules Tailwind has no variant for are listed under Unsupported.
- The cascade is respected. If a later rule overrides a property from an earlier @media or :hover rule, as in .t6 above, the overridden declaration is listed rather than converted, because a md: class would win in Tailwind where your CSS lost.
- Assumptions. Tailwind's default theme and Preflight (on by default), 1rem = 16px. Classes from your own tailwind.config are not known, and selectors are not rewritten: put each class list on the element the selector targeted.
Sources
Checked on .
Frequently Asked Questions
Built by Derek Giordano · Part of Ultimate Design Tools