DEV Community

Junichi Takahashi
Junichi Takahashi

Posted on

How to set up Tailwind

Tailwind is a utility-first CSS framework.
This article describes how to set up Tailwind.

Install

npm i --save-dev tailwindcss
Enter fullscreen mode Exit fullscreen mode

Init

npx tailwindcss init
Enter fullscreen mode Exit fullscreen mode

Setting

// tailwind.config.js

module.exports = {
  content: ["./src/**/*.{html,js}"],
  theme: {
    extend: {},
  },
  plugins: [],
};
Enter fullscreen mode Exit fullscreen mode

Write

/* src/index.css */

@tailwind base;
@tailwind components;
@tailwind utilities;
Enter fullscreen mode Exit fullscreen mode

Build

npx tailwindcss build -i ./src/index.css -o ./dist/index.css
Enter fullscreen mode Exit fullscreen mode

Using Tailwind in Page

<!-- src/index.html -->

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="/dist/index.css" rel="stylesheet" />
  </head>
  <body>
    <p class="underline">Hello</p>
  </body>
</html>
Enter fullscreen mode Exit fullscreen mode

Check

serve .
Enter fullscreen mode Exit fullscreen mode

http://localhost:3000/src/index.html

Support for Visual Studio Code

// .vscode/extensions.json

{
  "recommendations": ["bradlc.vscode-tailwindcss"]
}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)