Course contentsShow
← Web Development
Lesson 606 of 2,98211. Utility-First CSS with TailwindFree lesson

Installing Tailwind CSS

Set up Tailwind in a project using npm, including PostCSS and autoprefixer dependencies.

Installing Tailwind CSS

You'll learn how to set up Tailwind CSS in a project using npm, including its required dependencies.

Now that you understand what utility-first CSS is, it's time to get Tailwind CSS running in your own project. Unlike traditional CSS frameworks where you just link a stylesheet, Tailwind requires a build step because it generates classes on-demand and can be customized extensively.

The Installation Process

Think of installing Tailwind like setting up a custom workshop—you need the right tools before you can start building. Tailwind relies on PostCSS (a tool for transforming CSS) and autoprefixer (which adds browser-specific prefixes automatically) to process your styles.

Here's the installation sequence:

# Initialize npm in your project (if not already done)
npm init -y

# Install Tailwind and its dependencies
npm install -D tailwindcss postcss autoprefixer

# Generate Tailwind configuration files
npx tailwindcss init

The -D flag installs these as development dependencies since they're only needed during the build process, not in production.

What You Get

After installation, you'll have a tailwind.config.js file where you can customize your design system. You'll also need to configure PostCSS (usually in a postcss.config.js file) to tell it to use Tailwind and autoprefixer:

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  }
}

Finally, you create a CSS file that imports Tailwind's base styles, components, and utilities—but we'll cover that setup in the next lesson.

Key Takeaway: Installing Tailwind CSS requires npm and involves three core packages: tailwindcss, postcss, and autoprefixer, which work together to generate and process your utility classes during development.