Tailwind installieren und konfigurieren
Richten Sie Tailwind CSS per CDN sowie per npm mit der CLI ein und sehen Sie zu, wie Ihre erste formatierte HTML-Seite zum Leben erwacht.
Tailwind installieren und konfigurieren ist eine kostenlose Tailwind CSS Academy-Lektion auf CoddyKit. Dies ist Lektion 2 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Tailwind CSS Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Tailwind CSS Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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 -pThe 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 --minifyLinking 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 devTailwind 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 startTailwind 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.
Häufig gestellte Fragen
Ist die Lektion „Tailwind installieren und konfigurieren“ kostenlos?
Ja — der vollständige Text von „Tailwind installieren und konfigurieren“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Tailwind CSS Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Tailwind CSS Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Tailwind installieren und konfigurieren“?
Richten Sie Tailwind CSS per CDN sowie per npm mit der CLI ein und sehen Sie zu, wie Ihre erste formatierte HTML-Seite zum Leben erwacht. Du übst Tailwind CSS Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Tailwind CSS Academy zu starten?
Keine Vorkenntnisse erforderlich. Tailwind CSS Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 2 von 4.
Wie lange dauert die Lektion „Tailwind installieren und konfigurieren“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Tailwind CSS Academy-Lektion Code schreiben und ausführen?
Ja. Jede Tailwind CSS Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Utility-First-CSS erklärt
- Tailwind installieren und konfigurieren
- Ihre erste Tailwind-Seite
- Tailwind im Vergleich zu traditionellem CSS