Learn how to get Tailwind CSS up and running in your project.
npm init
📁 project
- 📁 public
- 📁 css
- index.html
- 📁 src
- 📁 css
- package.json
For most projects (and to take advantage of Tailwind's customization features), you'll want to install Tailwind and its peer-dependencies via npm.
npm install -D tailwindcss@latest postcss-cli@latest autoprefixer@latest
npx tailwindcss init -p
This will create a postcss.config.js
file and a minimaltailwind.config.js
file at the root of your project:
// postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
}
}
// tailwind.config.js
module.exports = {
purge: [],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {},
plugins: [],
}
@tailwind base;
@tailwind components;
@tailwind utilities;
When building for production, be sure to configure the purge
option to remove any unused classes for the smallest file size:
// tailwind.config.js
module.exports = {
purge: [
'public/*.html',
],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {},
plugins: [],
}
.
.
.
"scripts": {
"watch:css": "postcss ./src/css/**/*.css -o ./public/css/style.css -w",
"build:css": "postcss ./src/css/style.css -o ./public/css/style.css",
"production:css": "NODE_ENV=production postcss ./src/css/style.css -o ./public/css/style.css"
},
.
.
.
Now you can use the scripts, for example: npm run build:css
.