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 CLI

The simplest and fastest way to get up and running with Tailwind CSS from scratch is with the Tailwind CLI tool. The CLI is also available as a standalone executable if you want to use it without installing Node.js.

Installation - 图1

  1. Install Tailwind CSS

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

    Terminal

    Installation - 图2

    1. npm install -D tailwindcssnpx tailwindcss init
  2. Configure your template paths

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

    tailwind.config.js

    Installation - 图3

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

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

    src/input.css

    Installation - 图4

    1. @tailwind base;
    2. @tailwind components;
    3. @tailwind utilities;
  4. Start the Tailwind CLI build process

    Run the CLI tool to scan your template files for classes and build your CSS.

    Terminal

    Installation - 图5

    1. npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch
  5. Start using Tailwind in your HTML

    Add your compiled CSS file to the <head> and start using Tailwind’s utility classes to style your content.

    src/index.html

    Installation - 图6

    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/output.css" rel="stylesheet">
    7. </head>
    8. <body>
    9. <h1 class="text-3xl font-bold underline">
    10. Hello world!
    11. </h1>
    12. </body>
    13. </html>

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

  • Utility-First FundamentalsInstallation - 图7

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

  • Responsive DesignInstallation - 图8

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

  • Hover, Focus & Other StatesInstallation - 图9

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

  • Dark ModeInstallation - 图10

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

  • Reusing StylesInstallation - 图11

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

  • Customizing the FrameworkInstallation - 图12

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