0Pricing
Tailwind CSS Academy · レッスン

Tailwindのインストールと設定

CDN経由、およびCLI付きのnpm経由でTailwind CSSをセットアップし、初めてスタイルを適用したHTMLページが形になる過程を確認します。

「Tailwindのインストールと設定」はCoddyKit上の無料Tailwind CSS Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはTailwind CSS Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Tailwind CSS Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Two Ways to Add Tailwind

Two ways to add Tailwind: a CDN script tag for quick prototyping, or the npm CLI for production, which builds a tiny optimized CSS file.

<!-- CDN approach (prototyping only) -->
<script src="https://cdn.tailwindcss.com"></script>

Installing Tailwind via npm

For production, install via npm: tailwindcss, postcss, and autoprefixer. Then run npx tailwindcss init -p to create both config files at once.

npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

The tailwind.config.js File

The tailwind.config.js file has one key field to set first: content. List every file that uses Tailwind classes, or those classes get left out of your build.

// tailwind.config.js
module.exports = {
  content: [
    './index.html',
    './src/**/*.{html,js,jsx,ts,tsx,vue,svelte}',
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};

The PostCSS Config File

Tailwind runs as a PostCSS plugin. The postcss.config.js file tells your bundler to run it. Most tools pick it up automatically — you rarely touch it again.

// postcss.config.js
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};

Creating Your Main CSS File

Make a CSS entry file and add the three @tailwind directives: base, components, and utilities. At build time they expand into Tailwind generated styles.

/* src/input.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

Running the Tailwind CLI

The Tailwind CLI watches your files and rebuilds on save. Point --input and --output at your files, add --watch for dev, and --minify for production.

# Development (with watch)
npx tailwindcss -i ./src/input.css -o ./dist/output.css --watch

# Production (minified)
npx tailwindcss -i ./src/input.css -o ./dist/output.css --minify

Linking the CSS in HTML

Now link the generated CSS in your HTML like any stylesheet. Point href at the output file, not the input, and every utility class starts working.

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

Tailwind With Vite

Using Vite? Tailwind plugs in through PostCSS. Set up the configs, import your CSS in main.js, and Vite handles the rest with instant hot reloading.

// main.js (Vite entry point)
import './src/input.css';

// Then run:
npm run dev

Tailwind With Create React App

On Create React App, install the packages, init the config, and import index.css with the directives. CRA already runs PostCSS, so just restart the server.

# 1. Install dependencies
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p

# 2. Add directives to src/index.css
# @tailwind base;
# @tailwind components;
# @tailwind utilities;

# 3. Start dev server
npm start

Tailwind Preflight: The CSS Reset

The @tailwind base line injects Preflight, a gentle reset. It clears default margins, sets box-sizing everywhere, and gives you a clean, consistent baseline.

/* Preflight effects (auto-applied): */
/* - All elements: box-sizing: border-box */
/* - Body: margin: 0 */
/* - h1-h6: font-size/weight reset to body defaults */
/* - ul/ol: list-style: none; margin: 0; padding: 0 */

Verifying Your Installation

To verify it works, add text-3xl font-bold text-indigo-600 to a heading. Big, bold, indigo? You are set. If not, check your content paths in the config.

<!-- Verification test -->
<h1 class="text-3xl font-bold text-indigo-600">
  If this is big, bold, and purple — Tailwind is working!
</h1>

Quick Check

Quick check! Make sure setup clicked. 🛠️

Lesson Recap

Great! Add Tailwind via CDN or npm, set content paths so classes ship, and add the three @tailwind directives. Next up: building your first page.

よくある質問

「Tailwindのインストールと設定」レッスンは無料ですか?

はい。「Tailwindのインストールと設定」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Tailwind CSS Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Tailwind CSS Academyコースには全4レッスンが含まれています。

「Tailwindのインストールと設定」で何を学びますか?

CDN経由、およびCLI付きのnpm経由でTailwind CSSをセットアップし、初めてスタイルを適用したHTMLページが形になる過程を確認します。 ブラウザで直接実行するハンズオンコードでTailwind CSS Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Tailwind CSS Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのTailwind CSS Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「Tailwindのインストールと設定」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このTailwind CSS Academyレッスンでコードを書いて実行できますか?

はい。すべてのTailwind CSS Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. ユーティリティファーストCSSの解説
  2. Tailwindのインストールと設定
  3. 初めてのTailwindページ
  4. Tailwindと従来のCSSの比較
← Tailwind CSS Academyに戻る