Xerobit

CSS to Tailwind Converter

Paste CSS declarations or whole rules and get Tailwind v3 utility classes back. Spacing, colors, font sizes, radii, shadows and layout map to exact default-theme classes. Anything else becomes an arbitrary value. It runs in your browser.

Result

.btn => inline-flex items-center py-2 px-4 text-sm font-semibold text-white bg-blue-500 rounded-md shadow-sm transition-all duration-200 ease-[cubic-bezier(0.42,0,0.58,1)] hover:bg-blue-600 md:py-3 md:px-6
  • Utility classes
    16
  • Arbitrary values
    1

    No exact default-theme utility. These use [..] syntax.

  • Not converted
    0

Arbitrary values: transition: all 0.2s ease-in-out. text-sm also sets line-height: 1.25rem. Use text-[14px] to change only the font size.

How to use the css to tailwind converter

  1. Paste CSS declarations (display: flex; padding: 16px;) or full rules with selectors into the CSS box.
  2. Read the classes. For plain declarations you get one class list, and for rules you get one line per selector, with hover:, md: and similar variants added.
  3. Check the note for arbitrary values, which are written as [..], and for declarations that were not converted.
  4. Copy the classes into your class or className attribute and remove the old CSS.

How this CSS to Tailwind converter picks classes

Each declaration is matched against the Tailwind CSS v3 default theme. The converter reads the number and unit, turns rem into pixels at 16px, and looks for an exact match in the spacing scale, the palette, the font size scale, the radius scale or the shadow list. padding: 16px and padding: 1rem both become p-4, and background-color: #3b82f6 becomes bg-blue-500.

When no exact utility exists, the value is kept as written in square brackets, for example p-[13px] or bg-[#123456]. A property Tailwind has no utility for becomes an arbitrary property such as [animation:spin_1s_linear_infinite]. Nothing is rounded to a nearby value, so the generated classes produce the same CSS as your input.

Spacing scale: pixels to Tailwind classes

The default spacing scale is the same for padding, margin, gap, width, height and inset. A step of 1 is 0.25rem, which is 4px.

CSS valueremClass (padding shown)
4px0.25remp-1
8px0.5remp-2
12px0.75remp-3
16px1remp-4
20px1.25remp-5
24px1.5remp-6
32px2remp-8
40px2.5remp-10
48px3remp-12
64px4remp-16

Margins and inset values can be negative, which gives -mt-4 or -left-2. A value of auto gives mx-auto. Shorthands collapse: margin: 0 auto becomes my-0 mx-auto, and four equal sides become a single class.

Colors, font sizes and borders

Colors are matched by their exact hex value in the default palette. Short hex, uppercase hex, rgb() and hsl() are all normalized first. A color with alpha becomes an opacity modifier, so rgba(0, 0, 0, 0.5) is bg-black/50.

HexTailwind color
#3b82f6blue-500
#ef4444red-500
#22c55egreen-500
#f59e0bamber-500
#6b7280gray-500
#8b5cf6violet-500
Font sizeClassLine height set by the class
12pxtext-xs16px
14pxtext-sm20px
16pxtext-base24px
18pxtext-lg28px
20pxtext-xl28px
24pxtext-2xl32px
30pxtext-3xl36px
36pxtext-4xl40px

Note that text-sm sets a line height as well as a font size. If your CSS has only font-size, the converter adds a note, and text-[14px] changes the size alone. Border radius maps 4px to rounded, 6px to rounded-md, 8px to rounded-lg and 9999px to rounded-full.

Selectors, pseudo-classes and media queries

When the input has rules, the converter groups classes by selector. A simple class selector with pseudo-classes becomes variants: :hover is hover:, :first-child is first:, and ::before is before:. A min-width media query that matches a breakpoint becomes sm:, md:, lg:, xl: or 2xl: (640, 768, 1024, 1280 and 1536 pixels). Other widths use min-[500px]:. Selectors with descendant combinators cannot be expressed as a variant, so the converter lists the classes and tells you to put them on the matching element.

!important becomes the ! modifier, as in !text-white. If a property is repeated in one rule, only the last value is kept, as in the cascade.

Tailwind to CSS: reading classes the other way

To go from Tailwind to CSS, look up the class in the default theme. This converter works only in the CSS to Tailwind direction, but the table shows what common utilities expand to.

Tailwind classCSS
p-4padding: 1rem
mx-automargin-left: auto; margin-right: auto
w-1/2width: 50%
text-smfont-size: 0.875rem; line-height: 1.25rem
font-boldfont-weight: 700
rounded-lgborder-radius: 0.5rem
opacity-50opacity: 0.5
z-10z-index: 10

If your project customizes tailwind.config.js, the class names for your own spacing or colors can differ from these defaults. For the stylesheet side, the CSS formatter and CSS minifier help, and the Tailwind gradient generator builds gradient classes. Coming from a preprocessor? Compile first with the LESS to CSS converter or the SCSS to CSS converter.

Worked examples

ExampleInputResult
Button rule with hover and breakpointCSS: .btn { / display: inline-flex; / align-items: center; / padding: 8px 16px; / font-size: 14px; / font-weight: 600; / color: #ffffff; / background-color: #3b82f6; / border-radius: 6px; / box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); / transition: all 0.2s ease-in-out; / } / .btn:hover { background-color: #2563eb; } / @media (min-width: 768px) { / .btn { padding: 12px 24px; } / }Utility classes: 16; Arbitrary values: 1; Not converted: 0
Declarations onlyCSS: display: flex; / align-items: center; / justify-content: space-between; / gap: 16px; / padding: 24px; / background-color: #f9fafb;Utility classes: 6; Arbitrary values: 0; Not converted: 0
Values that need arbitrary classesCSS: width: 237px; / margin-top: 13px; / color: #123456; / font-size: 15px; / animation: spin 1s linear infinite;Utility classes: 5; Arbitrary values: 5; Not converted: 0
Card with border and shadowCSS: .card { / border: 1px solid #e5e7eb; / border-radius: 12px; / box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1); / padding: 24px; / max-width: 448px; / }Utility classes: 7; Arbitrary values: 0; Not converted: 0

FAQ

How do I convert CSS to Tailwind?

Paste the CSS into the converter. Each declaration is matched to a Tailwind v3 utility, such as display: flex to flex and padding: 16px to p-4, and values without an exact match become arbitrary values in square brackets.

Does it use Tailwind v3 or v4 class names?

Tailwind v3, using the default theme. A project that customizes its theme, or that uses v4 with a different default scale, can need different class names.

What is an arbitrary value?

It is a class with the exact value in square brackets, like w-[237px] or bg-[#123456]. Tailwind v3 generates the CSS for it on demand, so the result matches your original declaration.

Can I convert Tailwind to CSS with this tool?

No, it converts CSS to Tailwind. To go back, look the class up in the theme. The table above shows the CSS for common utilities.

Why does text-sm appear for a plain font-size?

text-sm is the exact class for 14px, but it also sets line-height: 1.25rem. When you want only the font size, use the arbitrary form such as text-[14px].

Is my CSS uploaded?

No. The conversion runs in your browser and nothing is sent to a server.

Sources and references