Tailwind CSS - The Basics
An introduction to Tailwind CSS, a utility-first CSS framework that streamlines styling with low-level utility classes.

Tailwind CSS - The Basics
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.
Why utility-first?
- Predictability: Each utility does exactly one thing. There is little surprise about what
mt-6orgap-4will do. - Consistency: Reusing utilities across components keeps spacing, typography, and colors consistent without copying CSS rules.
- Speed of iteration: You change UI by editing HTML/JSX classes, which is faster than switching between markup and stylesheets.
Getting started (quick)
- Install Tailwind with your build setup. For PostCSS-based or modern frameworks the installation is typically:
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
- Configure
contentintailwind.config.jsso 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: [],
};
- Add the Tailwind directives to your main CSS file:
@tailwind base;
@tailwind components;
@tailwind utilities;
After that, you can apply utilities directly in your templates or components.
Core concepts
- Utility classes: Small, single-purpose classes like
text-sm,px-3,rounded-lg. - Responsive modifiers: Prefixes like
sm:,md:,lg:let you apply utilities at breakpoints:md:text-lg. - State variants:
hover:,focus:,active:and others allow state-based styling without custom CSS. - Design tokens via
theme: Tailwind exposes a centralized theme for colors, spacing, and fonts, which you can extend intailwind.config.js.
Customizing the theme
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.
Composition: extracting components
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@applyto compose utilities:
.btn-primary {
@apply bg-brand inline-flex items-center rounded-md px-4 py-2 text-white;
}
- Component wrappers: In React/Next.js, create small wrapper components that house common utility sets, e.g., a
Buttoncomponent that already includesbtn-primaryclasses.
Both approaches keep markup readable while preserving the benefits of utility-first styling.
Productivity tips and best practices
- Keep your
contentpaths accurate so unused utilities are purged in production. - Favor descriptive component wrappers for complex UIs to avoid very long class lists inline.
- Use
prettier-plugin-tailwindcssto automatically sort and group classes. This plugin reorders classes into a recommended, consistent order — great for collaboration and diffs. - Use
variantsandpluginswhen you need more advanced utilities (forms, typography, aspect-ratio, etc.). Tailwind Labs and the community offer useful official plugins.
Common gotchas
- Large bundles: Without proper
contentconfiguration, Tailwind adds the whole utility set. Always configure and build for production. - Readability: Long class strings can be intimidating. Break them into semantic components or use
@applywhen appropriate. - Specificity: If you mix traditional CSS and Tailwind utilities, remember Tailwind utilities have low specificity. Use component classes or
!importantsparingly.
Example workflow
- Prototype: Build the layout fast with utilities (spacing, grid, flex).
- Extract: Identify repeated patterns and extract them to components or
@applyclasses. - Polish: Customize
themetokens for brand colors, type scale, and spacing. - Optimize: Verify
tailwind.config.jscontentpaths and build for production to purge unused styles.
Conclusion
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:
- Add an example React/Next.js component using these utilities.
- Add a short code sandbox or Storybook snippet.
- Configure
prettier-plugin-tailwindcsssorting in your project and showprettiercommands to check formatting on save.
Let's build something great together
Have an idea you want to bring to life? Let's shape it into something you're proud to show.