- Node.js: Ensure you have Node.js installed, which includes
npm(Node Package Manager). Download it from nodejs.org.
-
Download and Install Node.js:
- Visit nodejs.org.
- Download the recommended version for your operating system.
- Follow the installation instructions.
-
Verify Installation: After installation, open your terminal and run:
node -v
This checks the Node.js version installed.
To check
npm:npm -v
If both commands return version numbers, Node.js and npm are installed correctly.
-
Using npx:
npxis included with npm, so if you have npm, you can use npx directly.
-
Create a New Directory for Your Project:
mkdir tailwind-html-project
- Explanation: Creates a new directory named
tailwind-html-project.
- Explanation: Creates a new directory named
-
Navigate into the Project Directory:
cd tailwind-html-project- Explanation: Changes the current directory to
tailwind-html-project.
- Explanation: Changes the current directory to
-
Create an
index.htmlFile: Open your text editor and create anindex.htmlfile with the following content:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Tailwind CSS Project</title> <link href="dist/styles.css" rel="stylesheet"> </head> <body> <h1 class="text-3xl font-bold">Hello, Tailwind CSS!</h1> </body> </html>
-
Create a Directory for Your Styles:
mkdir src
- Explanation: Creates a new directory named
srcto store your CSS files.
- Explanation: Creates a new directory named
-
Create a CSS File
src/styles.css: Add the following content:@tailwind base; @tailwind components; @tailwind utilities;
-
Run the Following Command to Create a Tailwind Config File:
npx tailwindcss init
- Explanation: Initializes Tailwind CSS and creates a
tailwind.config.jsfile.
- Explanation: Initializes Tailwind CSS and creates a
-
Update
tailwind.config.jsto Include Your HTML Files:module.exports = { content: ['./**/*.html'], // This includes all HTML files in the project theme: { extend: {}, }, plugins: [], }
-
To Build the CSS and Watch for Changes, Run:
npx tailwindcss -i ./src/styles.css -o ./dist/styles.css --watch
- Explanation: Processes
src/styles.cssand outputs todist/styles.css, watching for changes.
- Explanation: Processes
-
Open Your
index.htmlin a Browser to See the Result. The CSS will automatically update whenever you modifysrc/styles.css.
-
Command Not Found for Node or npm:
- If you see an error indicating that
nodeornpmis not found, ensure Node.js is installed correctly. Reinstall it if necessary.
- If you see an error indicating that
-
npxCommand Fails:- Ensure you have an up-to-date version of npm. Update npm using:
npm install -g npm@latest
- If the previous command doesn't help, try:
npm install -g npx
- Ensure you have an up-to-date version of npm. Update npm using:
-
Verify
npxInstallation:- After updating, check if npx is available by running:
npx -v
- After updating, check if npx is available by running:
-
Tailwind CSS Not Building:
- Check that your
tailwind.config.jsfile has the correct paths in thecontentarray to include all your HTML files. - Ensure you have created the
src/styles.cssfile with the proper Tailwind directives.
- Check that your
-
CSS Not Applying:
- Verify that the link to
dist/styles.cssis correctly included in your HTML file. - Ensure your HTML file is saved in the correct directory that matches the paths in the configuration.
- Verify that the link to
You now have a complete setup for Tailwind CSS in a basic HTML project, including a live watch feature. The guide explains each command and provides error handling tips. You can edit your styles in src/styles.css, and any changes will automatically reflect in your HTML files.
For further information and to see the project structure, check the tailwind-html-project folder in the repository. If you have any further questions, feel free to ask!