DevToolBoxGRÁTIS
Blog

Guia CSS to Tailwind Online: Converter Propriedades CSS em Classes de Utilitario

13 min de leituraby DevToolBox

TL;DR

Tailwind CSS replaces hand-written CSS with composable utility classes, cutting stylesheet bloat and speeding up UI development. Common conversions: display: flex becomes flex, padding: 16px becomes p-4, and media queries become responsive prefixes like md: and lg:. For complex or legacy projects, migrate incrementally component by component. Use arbitrary values like p-[13px] when the default scale does not fit. Our free CSS to Tailwind converter automates the mapping so you can focus on building. CSS to Tailwind Tool

Key Takeaways

  • Tailwind is a utility-first CSS framework that replaces custom class names with pre-built, composable utilities.
  • The spacing scale uses a 4px base: p-1 = 4px, p-2 = 8px, p-4 = 16px, m-8 = 32px.
  • Responsive design uses mobile-first breakpoint prefixes: sm:, md:, lg:, xl:, 2xl: instead of @media queries.
  • Arbitrary values in square brackets like w-[calc(100%-2rem)] handle any value outside the default scale.
  • Dark mode is built in: prefix any utility with dark: and configure darkMode in tailwind.config.js.
  • Tailwind purges unused classes in production, resulting in CSS bundles under 10 KB for most projects.Try it free.
  • Gradual migration is safer than a full rewrite: convert one component at a time and keep both systems running.
  • Tailwind is not ideal for every project: highly dynamic styles, third-party widget overrides, and email templates may be better served by traditional CSS.

What Is Tailwind CSS and Why Should You Migrate?

Tailwind CSS is a utility-first CSS framework that provides low-level utility classes like flex, pt-4, text-center, and rotate-90 directly in your HTML. Instead of writing custom CSS classes like .card-header-title, you compose styles from a set of constrained, single-purpose utilities.

Traditional CSS tends to grow unbounded over time. Every new feature adds new classes, specificity battles emerge, dead CSS accumulates, and refactoring becomes risky because you cannot tell which styles are still used. Tailwind solves these problems by co-locating styles with markup and automatically purging unused utilities in production.

Key benefits of migrating to Tailwind include: no naming fatigue (stop inventing names like .sidebar-nav-item-active), consistent design tokens (spacing, colors, and typography are constrained by the config), tiny production bundles (typically under 10 KB gzipped), rapid prototyping (style directly in HTML without switching files), and easy responsive design (breakpoint prefixes instead of media query blocks).

→ Try our free CSS to Tailwind converter now

CSS Property to Tailwind Class Mapping

The core of any CSS-to-Tailwind conversion is understanding how CSS properties map to utility classes. Here are the most common conversions you will encounter:

CSSTailwind
display: flexflex
display: gridgrid
display: nonehidden
position: relativerelative
position: absoluteabsolute
position: stickysticky
margin: 0 automx-auto
padding: 16pxp-4
padding: 8px 16pxpx-4 py-2
width: 100%w-full
height: 100vhh-screen
max-width: 640pxmax-w-xl
font-size: 14pxtext-sm
font-weight: 700font-bold
text-align: centertext-center
line-height: 1.5leading-normal
border-radius: 8pxrounded-lg
cursor: pointercursor-pointer
overflow: hiddenoverflow-hidden
opacity: 0.5opacity-50

For display properties: display: flex becomes flex, display: grid becomes grid, display: block becomes block, display: inline-block becomes inline-block, display: none becomes hidden, and display: inline-flex becomes inline-flex.

For positioning: position: relative becomes relative, position: absolute becomes absolute, position: fixed becomes fixed, position: sticky becomes sticky. Top, right, bottom, left values use top-0, right-4, bottom-auto, left-1/2.

For sizing: width: 100% becomes w-full, height: 100vh becomes h-screen, max-width: 640px becomes max-w-xl, min-height: 100% becomes min-h-full.

For box model: padding: 16px becomes p-4, margin: 0 auto becomes mx-auto, border-radius: 8px becomes rounded-lg, box-shadow: 0 1px 3px rgba(0,0,0,0.1) becomes shadow-sm.

For text: font-size: 14px becomes text-sm, font-weight: 700 becomes font-bold, text-align: center becomes text-center, line-height: 1.5 becomes leading-normal, letter-spacing: 0.05em becomes tracking-wide.

/* Traditional CSS */
.card {
  display: flex;
  flex-direction: column;
  padding: 16px;
  margin: 0 auto;
  max-width: 640px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.card-body {
  font-size: 14px;
  line-height: 1.6;
  color: #374151;
}

<!-- Tailwind equivalent -->
<div class="flex flex-col p-4 mx-auto max-w-xl bg-white rounded-lg shadow-sm">
  <h3 class="text-lg font-bold mb-2">Title</h3>
  <p class="text-sm leading-relaxed text-gray-700">Body text</p>
</div>

Responsive Design: Media Queries vs Tailwind Breakpoints

One of Tailwind's most compelling features is how it handles responsive design. Instead of writing @media (min-width: 768px) { ... } blocks, you prefix any utility with a breakpoint modifier.

Tailwind uses a mobile-first approach. Unprefixed utilities apply to all screen sizes. Breakpoint prefixes apply at that width and above. The default breakpoints are: sm (640px), md (768px), lg (1024px), xl (1280px), 2xl (1536px).

PrefixMin WidthCSS
sm:640px@media (min-width: 640px)
md:768px@media (min-width: 768px)
lg:1024px@media (min-width: 1024px)
xl:1280px@media (min-width: 1280px)
2xl:1536px@media (min-width: 1536px)
/* Traditional CSS: responsive container */
.container {
  padding: 8px;
  font-size: 14px;
}

@media (min-width: 768px) {
  .container {
    padding: 16px;
    font-size: 16px;
  }
}

@media (min-width: 1024px) {
  .container {
    padding: 24px;
    font-size: 18px;
    max-width: 1024px;
    margin: 0 auto;
  }
}

<!-- Tailwind equivalent (one line) -->
<div class="p-2 text-sm md:p-4 md:text-base lg:p-6 lg:text-lg lg:max-w-screen-lg lg:mx-auto">
  ...
</div>

This means text-sm md:text-base lg:text-lg starts small on mobile, increases at the md breakpoint, and increases again at lg. You can customize these breakpoints in tailwind.config.js under the screens key.

Flexbox and Grid: CSS vs Tailwind

Flexbox and Grid layouts are where Tailwind truly shines, replacing multi-line CSS blocks with a handful of utility classes.

For Flexbox: flex-direction: row becomes flex-row, flex-direction: column becomes flex-col, justify-content: center becomes justify-center, align-items: center becomes items-center, flex-wrap: wrap becomes flex-wrap, gap: 16px becomes gap-4.

/* CSS: Centered flex container */
.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

<!-- Tailwind -->
<div class="flex justify-center items-center gap-4 flex-wrap">

/* CSS: Sidebar layout */
.layout {
  display: flex;
  min-height: 100vh;
}
.sidebar { width: 256px; flex-shrink: 0; }
.main { flex: 1; }

<!-- Tailwind -->
<div class="flex min-h-screen">
  <aside class="w-64 shrink-0">...</aside>
  <main class="flex-1">...</main>
</div>

For CSS Grid: grid-template-columns: repeat(3, 1fr) becomes grid-cols-3, grid-template-rows: auto 1fr auto becomes grid-rows-[auto_1fr_auto], grid-column: span 2 becomes col-span-2, gap: 24px becomes gap-6.

/* CSS: Responsive card grid */
.card-grid {
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr;
}
@media (min-width: 768px) {
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .card-grid { grid-template-columns: repeat(3, 1fr); }
}

<!-- Tailwind (one line) -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">

/* CSS: Dashboard grid */
.dashboard {
  display: grid;
  grid-template-columns: 250px 1fr;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  min-height: 100vh;
}

<!-- Tailwind -->
<div class="grid grid-cols-[250px_1fr] grid-rows-[auto_1fr_auto] gap-4 min-h-screen">

Complex layout patterns like a responsive card grid only need one line: grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6. In traditional CSS, this requires a media query block for each breakpoint.

Colors, Spacing, and Typography in Tailwind

Spacing in Tailwind follows a 4px base unit scale. p-1 equals 4px, p-2 equals 8px, p-4 equals 16px, p-8 equals 32px, and so on. The same scale applies to margin (m-), gap (gap-), width (w-), and height (h-). Negative values use a dash prefix: -mt-4 for margin-top: -16px.

Tailwind ClassValue
p-0, m-00px
p-px, m-px1px
p-0.5, m-0.52px
p-1, m-14px
p-2, m-28px
p-3, m-312px
p-4, m-416px
p-6, m-624px
p-8, m-832px
p-12, m-1248px
p-16, m-1664px
p-24, m-2496px

Colors use a shade-based naming convention: text-blue-500, bg-gray-100, border-red-600. Shades range from 50 (lightest) to 950 (darkest). Opacity modifiers work inline: bg-black/50 for 50% opacity, text-white/80 for 80% opacity.

/* CSS: Custom colors and opacity */
.element {
  color: #1a73e8;
  background-color: rgba(0, 0, 0, 0.5);
  border-color: #dc2626;
}

<!-- Tailwind -->
<div class="text-[#1a73e8] bg-black/50 border-red-600">

/* CSS: Standard palette colors */
.success { color: #16a34a; }        /* text-green-600 */
.warning { color: #ca8a04; }        /* text-yellow-600 */
.error   { color: #dc2626; }        /* text-red-600 */
.info    { color: #2563eb; }        /* text-blue-600 */
.muted   { color: #6b7280; }        /* text-gray-500 */

Typography classes cover font size (text-xs through text-9xl), font weight (font-thin through font-black), line height (leading-none through leading-loose), letter spacing (tracking-tighter through tracking-widest), and font family (font-sans, font-serif, font-mono).

Custom Values with Arbitrary Value Syntax [...]

Tailwind's design system covers most common values, but real projects often need exact pixel values, specific colors, or unusual calculations. The arbitrary value syntax handles these cases by wrapping any CSS value in square brackets.

Examples: w-[calc(100%-2rem)] for calculated widths, p-[13px] for non-standard padding, text-[#1a73e8] for custom hex colors, bg-[rgb(255,100,50)] for RGB colors, grid-cols-[200px_1fr_200px] for custom grid columns (underscores replace spaces), top-[var(--header-height)] for CSS custom properties.

<!-- Arbitrary values in Tailwind -->

<!-- Exact pixel values -->
<div class="w-[327px] h-[200px] p-[13px] m-[7px]">

<!-- Calculated values -->
<div class="w-[calc(100%-2rem)] h-[calc(100vh-64px)]">

<!-- Custom colors -->
<div class="text-[#1a73e8] bg-[rgb(255,100,50)] border-[hsl(220,90%,56%)]">

<!-- CSS custom properties -->
<div class="bg-[var(--brand-color)] top-[var(--header-height)]">

<!-- Custom grid columns (underscores = spaces) -->
<div class="grid grid-cols-[200px_1fr_200px]">

<!-- Arbitrary properties (no utility exists) -->
<div class="[clip-path:circle(50%)] [writing-mode:vertical-rl]">

<!-- Arbitrary variants -->
<div class="[&>*:first-child]:mt-0 [&_p]:text-gray-700">

You can also use arbitrary properties for CSS properties that Tailwind does not have utilities for: [clip-path:circle(50%)], [writing-mode:vertical-rl]. This escape hatch means you never need to fall back to a separate stylesheet for one-off styles.

Tailwind Config: Extending vs Overriding

The tailwind.config.js file controls your design system. Understanding the difference between extend and direct configuration is crucial.

When you add values under theme.extend, they are merged with the default theme. Your custom values are added alongside the defaults. When you add values directly under theme (not inside extend), the defaults for that category are completely replaced.

// tailwind.config.js

module.exports = {
  content: ['./src/**/*.{js,ts,jsx,tsx}'],
  darkMode: 'class', // or 'media'
  theme: {
    // EXTEND: adds to defaults (recommended)
    extend: {
      colors: {
        brand: {
          50:  '#eff6ff',
          500: '#3b82f6',
          900: '#1e3a5f',
        },
      },
      spacing: {
        '18': '4.5rem',   // 72px
        '88': '22rem',     // 352px
      },
      fontFamily: {
        display: ['Inter', 'system-ui', 'sans-serif'],
      },
      borderRadius: {
        '4xl': '2rem',
      },
      screens: {
        '3xl': '1920px',  // extra-large breakpoint
      },
      keyframes: {
        fadeIn: {
          '0%': { opacity: '0', transform: 'translateY(10px)' },
          '100%': { opacity: '1', transform: 'translateY(0)' },
        },
      },
      animation: {
        fadeIn: 'fadeIn 0.3s ease-out',
      },
    },

    // OVERRIDE: replaces defaults entirely (use with caution)
    // colors: { ... }  <-- this would REMOVE all default colors
  },
  plugins: [],
};

For example, adding a custom color under theme.extend.colors keeps all default colors and adds yours. Adding colors directly under theme.colors removes all default colors and uses only yours. In most cases, you want to use extend to add to the defaults rather than replace them.

Dark Mode: CSS Media Queries vs Tailwind dark:

Tailwind provides a built-in dark mode system using the dark: prefix. Any utility can be conditionally applied in dark mode: bg-white dark:bg-gray-900, text-gray-900 dark:text-gray-100.

Tailwind supports two dark mode strategies. The media strategy uses the operating system's prefers-color-scheme preference automatically. The class strategy (also called selector in Tailwind v4) toggles dark mode based on a .dark class on a parent element, giving you manual control with JavaScript.

/* Traditional CSS: dark mode */
.card {
  background-color: white;
  color: #111827;
  border: 1px solid #e5e7eb;
}

@media (prefers-color-scheme: dark) {
  .card {
    background-color: #1f2937;
    color: #f9fafb;
    border-color: #374151;
  }
}

<!-- Tailwind equivalent (inline, no media query needed) -->
<div class="bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-50 border border-gray-200 dark:border-gray-700">

<!-- Toggle dark mode with JavaScript (class strategy) -->
<script>
  // Add 'dark' class to <html> element
  document.documentElement.classList.toggle('dark');
</script>

<!-- Common dark mode patterns -->
<body class="bg-white dark:bg-gray-950 text-gray-900 dark:text-gray-100">
  <nav class="bg-gray-100 dark:bg-gray-900 border-b border-gray-200 dark:border-gray-800">
  <button class="bg-blue-600 hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-400">

In traditional CSS, implementing dark mode requires duplicating nearly every color declaration inside a @media (prefers-color-scheme: dark) block or managing CSS custom properties. With Tailwind, you declare both modes inline: bg-white dark:bg-slate-800 text-black dark:text-white. No separate stylesheet, no specificity issues.

Animations and Transitions in Tailwind

Tailwind includes utility classes for common CSS transitions and animations, reducing the need for custom keyframe definitions.

For transitions: transition enables transitions on common properties (color, background, border, shadow, transform, opacity). transition-colors, transition-opacity, transition-transform target specific properties. Duration uses duration-150, duration-300, duration-500 (in milliseconds). Easing uses ease-in, ease-out, ease-in-out, ease-linear. Delay uses delay-100, delay-200, etc.

/* CSS: Button hover transition */
.btn {
  transition: background-color 200ms ease-in-out, transform 200ms ease-in-out;
}
.btn:hover {
  background-color: #2563eb;
  transform: scale(1.05);
}

<!-- Tailwind -->
<button class="transition-all duration-200 ease-in-out hover:bg-blue-600 hover:scale-105">

/* CSS: Fade-in animation */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.3s ease-out; }

<!-- Tailwind (using config-defined animation) -->
<div class="animate-fadeIn">

<!-- Built-in animations -->
<svg class="animate-spin h-5 w-5">        <!-- Loading spinner -->
<span class="animate-ping absolute ...">  <!-- Notification dot -->
<div class="animate-pulse bg-gray-200">   <!-- Skeleton loader -->
<div class="animate-bounce">              <!-- Scroll indicator -->

For transforms: scale-95, rotate-45, translate-x-4, skew-y-3 apply transforms directly. Combine with hover: for interactive effects: hover:scale-105 transition-transform duration-200.

For animations: Tailwind ships with animate-spin, animate-ping, animate-pulse, and animate-bounce. For custom keyframe animations, define them in tailwind.config.js under theme.extend.keyframes and theme.extend.animation, then use them as animate-[yourName].

When NOT to Use Tailwind

Tailwind is powerful, but it is not the right choice for every situation. Recognizing when traditional CSS is better saves time and frustration.

  • Complex multi-step animations — Intricate @keyframes sequences with many steps are cleaner in a CSS file than as config entries.
  • Highly dynamic styles — When style values come from JavaScript variables at runtime (e.g., user-chosen colors, drag positions), inline styles or CSS custom properties are simpler than constructing class names dynamically.
  • Third-party component libraries — Overriding styles in Material UI, Ant Design, or other component libraries often requires targeting internal class names with traditional CSS selectors.
  • Email HTML templates — Email clients have severely limited CSS support. Inline styles are required, and Tailwind's utility approach does not map well to email constraints.
  • Very large legacy codebases — A big-bang migration is risky. Convert incrementally, component by component.
  • Teams unfamiliar with Tailwind — The learning curve is real. A team that writes clean BEM CSS may not benefit from switching to Tailwind if the project is near completion.

Migration Strategies: Gradual vs Full Rewrite

There are two main approaches to migrating an existing project from CSS to Tailwind: gradual migration and full rewrite.

Gradual migration (recommended for most projects): Install Tailwind alongside your existing CSS. Configure Tailwind to scan only the files you are actively converting. Migrate one component at a time, starting with the simplest leaf components. Once a component is fully converted, remove its old CSS. This approach is safe because both systems coexist, you can ship incrementally, and you can stop at any point.

# Gradual migration: Step-by-step

# 1. Install Tailwind alongside existing CSS
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

# 2. Configure content paths (scan only files you are converting)
# tailwind.config.js
module.exports = {
  content: ['./src/components/new/**/*.{js,jsx,ts,tsx}'],
  // ...
};

# 3. Add Tailwind directives to your CSS entry point
# app.css
@tailwind base;
@tailwind components;
@tailwind utilities;

/* Your existing CSS continues to work below */
@import './legacy-styles.css';

# 4. Convert one component at a time
# Before:  <div class="card-header">
# After:   <div class="flex items-center p-4 border-b border-gray-200">

# 5. Remove old CSS after each component is fully converted
# 6. Expand content paths as you convert more components

Full rewrite (suitable for small projects or complete redesigns): Replace all CSS files at once. This is faster for small projects but risky for large ones because you cannot ship partially. It works best when combined with a visual redesign, so you are rebuilding the UI anyway.

Regardless of approach, use automated tools to speed up the mechanical translation. Our CSS to Tailwind converter handles the property-to-utility mapping, letting you focus on component structure and responsive behavior.

→ Try the CSS to Tailwind converter now

Frequently Asked Questions

What is the fastest way to convert CSS to Tailwind classes?

Use an automated converter tool that maps CSS properties to their Tailwind equivalents. Paste your CSS, get the Tailwind classes instantly. For large projects, combine automated conversion with manual review to handle edge cases like complex selectors and pseudo-elements.

Does Tailwind increase HTML file size?

Yes, HTML files are slightly larger because class attributes contain more text. However, CSS bundle size decreases dramatically because Tailwind purges unused utilities in production. The net result is typically a smaller total transfer size because CSS compression is less efficient than HTML compression with gzip or Brotli.

Can I use Tailwind with CSS Modules or Styled Components?

Yes. Tailwind works alongside CSS Modules, Styled Components, Emotion, and other CSS-in-JS solutions. You can use Tailwind for layout and utility styles while using CSS Modules for complex component-specific styles. The @apply directive lets you extract Tailwind utilities into CSS classes if needed.

How do I handle hover, focus, and other pseudo-classes in Tailwind?

Tailwind uses state modifiers as prefixes: hover:bg-blue-600, focus:ring-2, active:scale-95, disabled:opacity-50, group-hover:text-white, first:mt-0, odd:bg-gray-50. These replace CSS pseudo-class selectors and work with any utility class.

What is the Tailwind spacing scale and how does it work?

Tailwind uses a 4px base unit for spacing. The scale goes: 0 (0px), px (1px), 0.5 (2px), 1 (4px), 1.5 (6px), 2 (8px), 2.5 (10px), 3 (12px), 4 (16px), 5 (20px), 6 (24px), 8 (32px), 10 (40px), 12 (48px), 16 (64px), 20 (80px), 24 (96px). Use arbitrary values like p-[13px] for non-standard spacing.

How does Tailwind handle responsive images and aspect ratios?

Tailwind provides aspect-auto, aspect-square, and aspect-video utilities. For responsive images, combine w-full with h-auto. For object-fit behavior, use object-cover, object-contain, object-fill. The aspect-ratio plugin (now built-in since v3.0) handles custom ratios like aspect-[4/3].

Should I use @apply to extract repeated utility patterns?

Use @apply sparingly. The Tailwind team recommends using component abstractions (React components, Vue components, partials) to avoid repetition rather than @apply. Reserve @apply for cases where you cannot use a component, such as styling third-party HTML or CMS content. Overusing @apply defeats the purpose of utility-first CSS.

How do I migrate CSS custom properties (variables) to Tailwind?

You can reference CSS custom properties directly in Tailwind using arbitrary values: bg-[var(--brand-color)], text-[var(--heading-size)]. Alternatively, map your custom properties to Tailwind theme values in tailwind.config.js. Tailwind v4 natively uses CSS custom properties for its design tokens, making integration seamless.

Conclusion

Migrating from CSS to Tailwind is a strategic investment that pays off with smaller bundles, faster development, and consistent design. Start with an automated converter for the mechanical translation, then refine component by component. For new components, write Tailwind from scratch. For legacy code, migrate gradually. The result is a codebase where styles are co-located with markup, dead CSS is eliminated automatically, and responsive design is expressed inline rather than in separate media query blocks.

Convert your CSS to Tailwind classes instantly with our free tool.

𝕏 Twitterin LinkedIn
Isso foi útil?

Fique atualizado

Receba dicas de dev e novos ferramentas semanalmente.

Sem spam. Cancele a qualquer momento.

Try These Related Tools

TWCSS to Tailwind🎨CSS Beautifier🎨CSS FormatterTWTailwind CSS Color Picker

Related Articles

CSS Flexbox Generator — Visual Flexbox Layout Builder

Complete guide to CSS Flexbox Generator. Learn flexbox axes, container properties (display, flex-direction, justify-content, align-items, flex-wrap, gap), item properties (flex-grow, flex-shrink, flex-basis, order, align-self), common layouts (navbar, card grid, holy grail, sidebar), flexbox vs grid, responsive patterns, and accessibility.

SVG para React Online: O guia completo para converter SVG em componentes React

Aprenda a converter SVG em componentes React com SVGR, otimizacao SVGO, conversao de atributos JSX, componentes de icones reutilizaveis, acessibilidade, animacao e tree-shaking.

Acessibilidade Web WCAG 2.2: ARIA, HTML semântico e testes

Guia completo WCAG 2.2 — papéis ARIA, HTML semântico e ferramentas de teste.