Skip to content

CSS to Tailwind Converter

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].

📖
Deep Dive: The Complete CSS to Tailwind Guide
Spacing scale, color system, flexbox mapping, arbitrary values, responsive variants, and when not to convert — everything this tool does and what it can't do for you.
→

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 CSSClasses written
margin: 0 automy-0 mx-auto
margin: 8px 16pxmx-4 my-2
padding: 13px 7px 2pxpb-0.5 pt-[13px] px-[7px]
font-size: 14px; line-height: 20pxtext-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: #333text-[#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]

Sources

Checked on .

Frequently Asked Questions

What Tailwind version does this target?+
Tailwind CSS v3 conventions. This is the most widely used version, and most classes are compatible with v4 as well. If you need v4-specific changes like gap-y / gap-x syntax differences, verify the output against your version.
Does it handle arbitrary values?+
Yes. When no default class produces exactly your value, the tool writes Tailwind's arbitrary syntax: padding 13px becomes p-[13px], a two-value margin is split into mx-/my- utilities, spaces become underscores (shadow-[0_2px_8px_rgba(0,0,0,0.1)]) and a type hint is added where Tailwind needs one (text-[length:16px], bg-[position:10%_20%]). Properties with no utility become arbitrary properties such as [transition:all_0.3s_ease].
What happens with unsupported properties?+
Almost every property converts, as a named class or an arbitrary property. The Unsupported list shows the rest: media queries other than min-width, max-width, dark mode, reduced motion and print; selectors with pseudo-classes Tailwind has no variant for; @-rules such as @keyframes; and declarations overridden by a later rule.
Can I paste multiple rules at once?+
Yes. Each selector gets its own list of classes, :hover and similar pseudo-classes become hover: and friends, and @media (min-width: …) blocks become sm:, md:, lg:, xl: or 2xl: classes on the same selector. Selectors themselves are not translated: put each list on the element its selector matched.
Which Tailwind version does the converter target?+
Tailwind CSS 3.4.17 with its default theme; there is no version switch. Most of the output also works in Tailwind 4, which kept most class names and the arbitrary-value syntax, but v4 changed some defaults (colours in OKLCH, the default border colour, ring width), so check exact colours and borders if you build with v4.
What about custom values not in Tailwind’s default scale?+
They become arbitrary values such as w-[137px] or text-[#5c72e8]. Matching is exact: a value is mapped to a named class only if that class produces the identical CSS, so 15px stays p-[15px] instead of being rounded to p-4, and a colour one shade away stays an arbitrary colour.
How does the tool handle pseudo-classes and media queries?+
Pseudo-classes and pseudo-elements on the selector become variants (hover:, focus:, focus-visible:, active:, disabled:, first:, last:, odd:, even:, before:, after:, placeholder: and others). @media (min-width: …) becomes sm:, md:, lg:, xl: or 2xl: at Tailwind's breakpoints and min-[…]: otherwise; max-width, dark mode, reduced motion and print map to max-[…]:, dark:, motion-reduce:/motion-safe: and print:. Other queries and parent-dependent selectors (where group- or peer- would be needed) are listed as unsupported.
Will the output exactly match my source CSS?+
For what it converts, yes, and that was measured: on October 12, 2026, nine test rules (about 70 declarations, with :hover, @media, shorthands, colours, shadows and transitions) compiled with Tailwind 3.4.17 produced the same computed styles as the original CSS in Chromium in 27 of 27 checks. It assumes Tailwind's default theme and Preflight, and the selector itself is up to you: the classes must go on the element it matched.

Built by Derek Giordano · Part of Ultimate Design Tools

Privacy Policy · Terms of Service