Everything You Need To Know - From installing tailwindcss to deploying a tailwind website to production.

Everything You Need To Know - From installing tailwindcss to deploying a tailwind website to production.

ยท

3 min read

๐Ÿ–Œ๏ธ Tailwind CSS is an open-source, utility-based CSS Framework.

Why use tailwindcss?

  • You don't have to think of different class names again and again.
  • Tailwind provides a list of CSS classes which makes the process of styling more fun and easy.
  • You don't have to make two separate files (index.html & style.css) to design your websites. You can write tailwind css inside your HTML file.
  • When you make a change, there is no risk of breaking existing templates.
  • Tailwindcss also allows you to build responsive websites. In fact, it is easy compared to our actual css. By default, tailwind uses a mobile first breakpoint system.

A lot of people must have wondered, will tailwindcss slow down our websites, or will they increase the production bundle size, because there are so many classes inside one single file? Well, the answer is "NO".

Easiest way to install Tailwindcss

๐ŸŒ• As we know, there are many methods to install tailwindcss for our daily projects, and the easiest and most effortless way is the Play CDN ( But the worst part is Play CDN is only for development not for production. Suppose you want to make an important website and you are planning to deploy the website on GitHub or Netlify then working with Play CDN is not such a good idea. )

Steps To Set Up Tailwindcss

๐ŸŒ• Open the folder in VS Code and open the terminal.

Capture.JPG

๐ŸŒ• Type: npm init -y This initializes the directory as a NodeJs Project. This command will create a package where the project files will be stored and all the modules you download will be stored in the package.

Capture1.JPG

๐ŸŒ• Type: npm install -D tailwindcss postcss autoprefixer vite This step will install all the required packages and vite will help us start an instant server.

Capture2.JPG

๐ŸŒ• Type: npx tailwindcss init -p This will generate configuration files for tailwind CSS and postcss.

Capture3.JPG

๐ŸŒ• Open tailwind.config.js โžก๏ธ content: ["*"], This ( * ) means you want to use tailwindcss classes in all the files.

Capture4.JPG

๐ŸŒ• Make your HTML and CSS file and add the CSS file to your HTML file.

Capture5.JPG

๐ŸŒ• Now add the tailwind directive i.e; @tailwind base; @tailwind components; @tailwind utilities; to your CSS file.

Capture6.JPG

๐ŸŒ• After adding the tailwind directives to your CSS file, open package.json and add "start": "vite", inside your script in place of test and type npm run start on your terminal. This will automatically generate your webpage. Click the link on your terminal ( ctrl+click ) .

Capture7.JPG

๐ŸŒ• Now you are ready to write your tailwindcss project.

Capture9.JPG

Capture8.JPG

Deploying your tailwind website to production

Congratulation for making such a beautiful website with tailwindcss ๐Ÿ˜ƒ. Now it's time to deploy your website. So follow these steps:

๐ŸŒ• Again open your package.json and add "build": "vite build". After adding this line go to your terminal and type npm run build

capture10.png

๐ŸŒ• After you run build you will see a folder named dist will be created in your explorer. This will build your website inside the dist folder. This dist folder is all you need for your deployment.

Capture11.JPG

IMPORTANT:- Now, if you close VS Code and go to your project folder and open the dist folder with VS Code and open your project with live server you will see the same website you created a while back. This dist folder contains your whole website including the assets file ( CSS file, js file, any images etc ).

Capture12.JPG

If you want to deploy your website on GitHub or Netlify you can just drag and drop the dist folder.

That's it for now. ๐Ÿ˜‡

I hope I have helped you to understand the easiest installation process of tailwindcss.

Stick around, there is more to come. ๐Ÿฅณ

Tweeter handler: Sneha Purkayastha

ย