
Tailwind CSS is a utility-first CSS framework that shifts how we write styles. Instead of creating many custom class names and separate CSS files, Tailwind gives you a rich set of low-level utility classes (e.g., p-4, text-center, bg-blue-500) that you compose directly in your markup. This leads to faster iteration, easier theming, and highly predictable results once you get used to the mental model.
mt-6 or gap-4 will do.npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
content in tailwind.config.js so Tailwind can tree-shake unused utilities (very important for bundle size):// tailwind.config.js
module.exports = {
content: [
"./app/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx}",
],
theme: { extend: {} },
plugins: [],
};
@tailwind base;
@tailwind components;
@tailwind utilities;
After that, you can apply utilities directly in your templates or components.
text-sm, px-3, rounded-lg.sm:, md:, lg: let you apply utilities at breakpoints: md:text-lg.hover:, focus:, active: and others allow state-based styling without custom CSS.theme: Tailwind exposes a centralized theme for colors, spacing, and fonts, which you can extend in tailwind.config.js.Tailwind's power comes from a configurable theme. Rather than overriding styles in many places, you define or extend tokens once:
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: { brand: "#1c7ed6" },
spacing: { 72: "18rem" },
},
},
};
Now bg-brand and w-72 become available across your app.
While utility classes reduce the need for CSS, real projects still benefit from composability. Use one of these approaches:
@apply: Create semantic component classes in a CSS file with @apply to compose utilities:.btn-primary {
@apply bg-brand inline-flex items-center rounded-md px-4 py-2 text-white;
}
Button component that already includes btn-primary classes.Both approaches keep markup readable while preserving the benefits of utility-first styling.
content paths accurate so unused utilities are purged in production.prettier-plugin-tailwindcss to automatically sort and group classes. This plugin reorders classes into a recommended, consistent order — great for collaboration and diffs.variants and plugins when you need more advanced utilities (forms, typography, aspect-ratio, etc.). Tailwind Labs and the community offer useful official plugins.content configuration, Tailwind adds the whole utility set. Always configure and build for production.@apply when appropriate.!important sparingly.@apply classes.theme tokens for brand colors, type scale, and spacing.tailwind.config.js content paths and build for production to purge unused styles.Tailwind CSS changes how you approach styling by leaning into composition and small, reusable utilities. For many teams it speeds development, reduces CSS drift, and improves consistency. The learning curve is mainly a change in how you think about styles — once you adapt, Tailwind becomes a powerful tool for building predictable, maintainable UI quickly.
If you'd like, I can also:
prettier-plugin-tailwindcss sorting in your project and show prettier commands to check formatting on save.