Tailwind CSS
Tailwind
A utility-first CSS framework. Styling through class composition.
Tailwind
A utility-first CSS framework. Styling through class composition.
Tailwind CSS is a utility-first CSS framework. Instead of predefined components like Bootstrap, it styles elements by combining small utility classes. Because you design directly in HTML, you rarely need to write a separate CSS file.
Its core advantage is the JIT (Just-in-Time) compiler. Only the classes you use are included in the CSS, so the bundle size is small (usually under 10KB). Variants for responsive (sm:, md:, lg:), dark mode (dark:), and states (hover:, focus:, active:) can be written directly in class names, which makes development fast.
In Tailwind 4 (2024), the approach changed to customizing with CSS variables instead of a configuration file. Build speed improved 10x, and with CSS-first configuration, theme customization is possible without tailwind.config.js. The introduction of the Lightning CSS engine also reduced the dependency on PostCSS.
Tailwind works well with design systems. You can predefine colors, spacing, fonts, and so on, and use them consistently. Combined with logic-only component libraries such as Headless UI and Radix UI, fully custom designs are possible.
<!-- Tailwind CSS ๊ธฐ๋ณธ ์ฌ์ฉ -->
<!-- ์นด๋ ์ปดํฌ๋ํธ -->
<div class="max-w-sm rounded-xl overflow-hidden shadow-lg
bg-white dark:bg-gray-800
hover:shadow-xl transition-shadow">
<img class="w-full h-48 object-cover" src="/image.jpg" alt="...">
<div class="p-6">
<h2 class="text-xl font-bold mb-2
text-gray-900 dark:text-white">
์ ๋ชฉ
</h2>
<p class="text-gray-600 dark:text-gray-300 text-sm">
์ค๋ช
ํ
์คํธ
</p>
</div>
</div>
<!-- ๋ฐ์ํ ๊ทธ๋ฆฌ๋ -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
<!-- ๋ชจ๋ฐ์ผ: 1์ด, ํ๋ธ๋ฆฟ: 2์ด, ๋ฐ์คํฌํฑ: 3์ด -->
<div class="bg-white p-4 rounded-lg">Item 1</div>
<div class="bg-white p-4 rounded-lg">Item 2</div>
<div class="bg-white p-4 rounded-lg">Item 3</div>
</div>
<!-- ๋ฒํผ ์ปดํฌ๋ํธ (React) -->
<button
className={`
px-4 py-2 rounded-lg font-medium
transition-colors duration-200
${variant === 'primary'
? 'bg-blue-600 text-white hover:bg-blue-700 active:bg-blue-800'
: 'bg-gray-200 text-gray-800 hover:bg-gray-300'
}
${disabled ? 'opacity-50 cursor-not-allowed' : ''}
`}
disabled={disabled}
>
{children}
</button>
<!-- Tailwind 4 - CSS-first ์ค์ -->
<style>
@import "tailwindcss";
/* CSS ๋ณ์๋ก ํ
๋ง ์ปค์คํฐ๋ง์ด์ง */
@theme {
--color-primary: #3b82f6;
--color-secondary: #10b981;
--font-display: "Inter", sans-serif;
--breakpoint-3xl: 1920px;
}
</style>
<!-- ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ํด๋์ค ์ถ์ถ (@apply) -->
<style>
.btn-primary {
@apply px-4 py-2 bg-blue-600 text-white rounded-lg
hover:bg-blue-700 active:bg-blue-800
transition-colors duration-200
focus:ring-2 focus:ring-blue-500 focus:ring-offset-2;
}
.input-field {
@apply w-full px-4 py-2 border border-gray-300 rounded-lg
focus:border-blue-500 focus:ring-2 focus:ring-blue-200
dark:bg-gray-800 dark:border-gray-600;
}
</style>
<!-- clsx/tailwind-merge๋ก ์กฐ๊ฑด๋ถ ํด๋์ค -->
import { clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
function cn(...inputs) {
return twMerge(clsx(inputs));
}
<button className={cn(
'px-4 py-2 rounded',
isActive && 'bg-blue-600',
!isActive && 'bg-gray-200',
className // props๋ก ๋ฐ์ ํด๋์ค ๋ณํฉ
)}>
In technology selection:
"I don't like the runtime overhead of CSS-in-JS. Tailwind generates CSS at build time, so there's no runtime cost, and thanks to JIT the bundle is small too. Design tokens can also be managed with tailwind.config, so it's well suited to design systems."
In a technical interview:
"What are the downsides of Tailwind?" - "Long class lists can reduce readability. You can extract them with @apply or abstract them into components, but team conventions are important. When the design changes, you may have to modify multiple files."
In a code review:
"The classes are too long. I think we should pull this out into a component." - "Right. If something repeats three or more times or forms a clear semantic unit, we extract it into a component. Managing it with a variant pattern using cva (class-variance-authority) makes it cleaner."
Take a mock interview on this topic โ WIA SOOM AI Interview ยท Start for free