Tailwind CSS
Tailwind CSS is a CSS framework that can produce minimum classes for your app. It means the CSS file only contains the required classes for your app. So the CSS file can be compact. It will be perfect for production.
It is better than traditional or other CSS frameworks that load all classes. In Tailwind CSS, we utilize the code to approach the design then produce the production version of it. Technically, it loads all classes then produces the minified version and contains only used classes.
You can visit this page to get started, https://tailwindcss.com/docs/installation. Many integration guides let you work with many frameworks such as React, Vue, or Laravel. You also can install Tailwind CSS as a PostCSS plugin. Here, let me show you the minimum usage of Tailwind CSS using Tailwind CLI. The minimum usage means we work without any framework or tool such as React, Vue, Laravel, or PostCSS. Just pure CSS or Tailwind CSS. Maybe you get confused to start with the official documentation.
- First, let's create the
package.json
file bynpm init
. npm install -D tailwindcss@latest postcss@latest autoprefixer@latest
to install Tailwind CSS, PostCSS, and Autoprefixer.npx tailwindcss init
to create thetailwind.config.js
file.npm install @tailwindcss/forms
to install the form plugin. Then add the plugin to thetailwind.config.js
file. Because sometimes we need form elements. More information is on https://github.com/tailwindlabs/tailwindcss-forms- Add
npx tailwindcss -i ./tailwind.css -o ./app.css --watch
as adev
script to thepackage.json
. - Add
NODE_ENV=production npx tailwindcss -i ./tailwind.css -o ./app.css --minify
as aprod
script to thepackage.json
.
Here is an example of package.json
.
|
|
Here is an example of tailwind.config.js
. The purge
field means it will read the file to scan the used classes.
|
|
Here is the basic of tailwind.css
.
|
|
We can use npm run dev
while development and npm run prod
while production. Feel free to clone this repository, https://github.com/aristorinjuang/tailwindcss.