Skip to content

Tailwind CSS - Home

Quick Start | Core Concepts | Best Practices | Resources

Tailwind CSS is a modern, utility-first CSS framework designed for building bespoke user interfaces with speed and precision. Instead of shipping pre-styled components, Tailwind provides low-level utility classes that you compose directly in your HTML to bring your unique designs to life.

  • Unmatched Customization: Build any design you can imagine without ever leaving your HTML or writing a single line of custom CSS.
  • Lightning-Fast Workflow: The utility-first approach eliminates context switching, keeping you focused on building.
  • Hyper-Optimized Performance: The Just-in-Time (JIT) compiler generates only the styles you actually use, resulting in tiny CSS bundles and lightning-fast load times.
  • Responsive by Design: Creating complex responsive layouts is intuitive with built-in, composable screen-size prefixes like md: and lg:.
  • Guaranteed Consistency: Work from a predefined design system of colors, spacing, and typography to ensure your UI is consistent and professional.
  • Thriving Ecosystem: With official plugins like Typography and Forms, and integration with all modern frontend frameworks, Tailwind fits perfectly into any stack.

While you can use the Play CDN for quick demos, the recommended way to use Tailwind in a real project is by installing it via a package manager. This unlocks Tailwind’s full potential, including customization and performance optimization.

Follow these steps to set up a new project:

# 1. Install Tailwind CSS
# Using npm
npm install -D tailwindcss
# Or using yarn
yarn add -D tailwindcss
# 2. Create your configuration file
npx tailwindcss init
# This creates a `tailwind.config.js` file.

3. Configure your template paths: Open tailwind.config.js and tell Tailwind where to find your HTML and JS files so it can scan them for class names.

/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["./src/**/*.{html,js}"], // Adjust this to your project structure
theme: {
extend: {},
},
plugins: [],
}

4. Add the Tailwind directives to your CSS: Create a main CSS file (e.g., ./src/input.css) and add the following lines.

@tailwind base;
@tailwind components;
@tailwind utilities;

5. Start the build process: Run the Tailwind CLI to scan your templates and build your CSS file. Keep it running in the background as you work.

# Run this command in your terminal
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

6. Link the compiled CSS in your HTML: Finally, add the compiled output.css file to the <head> of your HTML.

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/dist/output.css" rel="stylesheet">
</head>
<body>
<h1 class="text-3xl font-bold text-blue-600">
Hello world!
</h1>
</body>
</html>

For prototyping or online fiddling, you can add Tailwind via a single <script> tag. Note that this is not recommended for production.

<!doctype html>
<html>
<head>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<!-- Your content here -->
</body>
</html>

To get the most out of Tailwind CSS, you should have a solid understanding of HTML and CSS. Knowledge of modern JavaScript frameworks (like React or Vue) and package managers (like npm) is beneficial but not required to start.

This tutorial series will guide you through Tailwind’s core concepts. Instead of memorizing every class, focus on understanding the underlying system.

Layout: Flexbox, Grid, Display, Position, Sizing, Spacing

Styling: Colors, Typography, Backgrounds, Borders, Effects, Filters

Interactivity: Hover/Focus States, Transitions, Animations

Responsiveness: Mobile-First Breakpoints (sm:, md:, lg:)

Customization: Configuring tailwind.config.js to match your brand

Q: My HTML looks messy with all these classes. Is this normal?

Section titled “Q: My HTML looks messy with all these classes. Is this normal?”

Yes, at first. But this perceived ‘mess’ is also highly readable and locally scoped. The modern solution is to create reusable components (e.g., in React/Vue) to encapsulate these long class strings, giving you the best of both worlds: maintainable components and the power of utilities.

Q: How is Tailwind CSS different from Bootstrap?

Section titled “Q: How is Tailwind CSS different from Bootstrap?”

Bootstrap provides pre-built components (.card, .btn-primary), which makes it fast for standard layouts but harder to customize. Tailwind provides low-level utilities, giving you complete freedom to build custom designs without fighting framework styles.

Q: How do I handle custom styling for forms or prose?

Section titled “Q: How do I handle custom styling for forms or prose?”

Tailwind has official first-party plugins for this. Use @tailwindcss/forms for beautiful, consistent form styles and @tailwindcss/typography for styling blocks of content like blog posts or documentation pages with a single .prose class.

# Install official plugins
npm install -D @tailwindcss/forms @tailwindcss/typography

Q: How do I center an element on the page?

Section titled “Q: How do I center an element on the page?”

For centering a block element horizontally, use mx-auto. For centering content both horizontally and vertically within a container, use Flexbox. Apply flex items-center justify-center to the parent container.

<!-- Center child in the middle of the screen -->
<div class="min-h-screen flex items-center justify-center">
<div>Centered Content</div>
</div>