Installation

Get started with Tailwind CSS

Tailwind CSS works by scanning all of your HTML files, JavaScript components, and any other templates for class names, generating the corresponding styles and then writing them to a static CSS file.

It’s fast, flexible, and reliable — with zero-runtime.

Installation

Installing Tailwind CSS as a PostCSS plugin

Installing Tailwind CSS as a PostCSS plugin is the most seamless way to integrate it with build tools like webpack, Rollup, Vite, and Parcel.

  1. Install Tailwind CSS

    Install tailwindcss and its peer dependencies via npm, and create your tailwind.config.js file.

    Terminal

    1. npm install -D tailwindcss postcss autoprefixernpx tailwindcss init
  2. Add Tailwind to your PostCSS configuration

    Add tailwindcss and autoprefixer to your postcss.config.js file, or wherever PostCSS is configured in your project.

    postcss.config.js

    1. module.exports = {
    2. plugins: {
    3. tailwindcss: {},
    4. autoprefixer: {},
    5. }
    6. }
  3. Configure your template paths

    Add the paths to all of your template files in your tailwind.config.js file.

    tailwind.config.js

    1. /** @type {import('tailwindcss').Config} */
    2. module.exports = {
    3. content: ["./src/**/*.{html,js}"],
    4. theme: {
    5. extend: {},
    6. },
    7. plugins: [],
    8. }
  4. Add the Tailwind directives to your CSS

    Add the @tailwind directives for each of Tailwind’s layers to your main CSS file.

    main.css

    1. @tailwind base;
    2. @tailwind components;
    3. @tailwind utilities;
  5. Start your build process

    Run your build process with npm run dev or whatever command is configured in your package.json file.

    Terminal

    1. npm run dev
  6. Start using Tailwind in your HTML

    Make sure your compiled CSS is included in the <head> (your framework might handle this for you), then start using Tailwind’s utility classes to style your content.

    index.html

    1. <!doctype html>
    2. <html>
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <link href="/dist/main.css" rel="stylesheet">
    7. </head>
    8. <body>
    9. <h1 class="text-3xl font-bold underline">
    10. Hello world!
    11. </h1>
    12. </body>
    13. </html>

Using PostCSS - 图1Are you stuck? Setting up Tailwind with PostCSS can be a bit different across different build tools. Check our framework guides to see if we have more specific instructions for your particular setup.Explore our framework guidesUsing PostCSS - 图2

Get familiar with some of the core concepts that make Tailwind CSS different from writing traditional CSS.

  • Utility-First FundamentalsUsing PostCSS - 图3

    Using a utility-first workflow to build complex components from a constrained set of primitive utilities.

  • Responsive DesignUsing PostCSS - 图4

    Build fully responsive user interfaces that adapt to any screen size using responsive modifiers.

  • Hover, Focus & Other StatesUsing PostCSS - 图5

    Style elements in interactive states like hover, focus, and more using conditional modifiers.

  • Dark ModeUsing PostCSS - 图6

    Optimize your site for dark mode directly in your HTML using the dark mode modifier.

  • Reusing StylesUsing PostCSS - 图7

    Manage duplication and keep your projects maintainable by creating reusable abstractions.

  • Customizing the FrameworkUsing PostCSS - 图8

    Customize the framework to match your brand and extend it with your own custom styles.