Tailwind CSS continues to grow in popularity as it's a framework which allows you to create beautiful websites without needing to write a single line of CSS, while also not making your website look like a template (looking at you Bootstrap websites).
When you go to install tailwind inside your project, the first command you'll come across is npm install -D tailwindcss
. This is fine if your frontend is a single-page application (SPA) or your backend is in Node.js. However, what if you are using server-side rendering (SSR) for the frontend and your backend is in Laravel, Django, or ASP.NET? One solution is to place the Tailwind CDN script in the head of your HTML. The problem with this is it forces the user to download every single CSS class in Tailwind instead of only the ones actually being used.
This is where the Tailwind standalone CLI tool helps. The CLI tool gives you all the benefits of using the npm Tailwind package, such as only bundling the classes you are actively using in your website, but without having to install Node in your project.
I'm sure most of you can figure out how to get the CLI tool setup in your project based on the instructions in the link above, but if you need the extra help:
- Go to the Tailwind GitHub and download the version of the CLI executable which matches the system you are running
- Place the executable in your project and rename it to
tailwindcss
(not necessary but will mean the following steps will work for everyone) - Add
tailwindcss
to your .gitignore (if you are using git) - Run the command
./tailwindcss init
and modifycontent: []
so it knows which directories to look in for Tailwind classes - Create a CSS file called
input.css
and place it wherever you will store your static files - In this CSS file add these three lines
@tailwind base;
@tailwind components;
@tailwind utilities;
- To use Tailwind and have it automatically compile the classes you use, run this command
./tailwind -i ./path/to/static/files/input.css -o ./path/to/static/files/output.css --watch
- output.css is the CSS file you will use in your website so add it to your HTML
- If you want to send an optimised version of your CSS file to your users, run this command
./tailwind -i ./path/to/static/files/input.css -o ./path/to/static/files/output.css --minify
As a framework, Tailwind CSS provides a great deal of freedom for you to design your websites the way you want them, while making it easy for you to do so. If you have been avoiding using Tailwind because of needing to install Node, I hope this tutorial has helped you in getting it setup in your project.🙂
Top comments (0)