Tailwind CSS

Tailwind CSS

Tailwind:

Tailwind is the CSS framework that is used for developing unique designs. Tailwind does not work like other CSS frameworks like Bootstrap and materializes it doesn’t come with predefined components. Tailwind provides you with a set of CSS helper classes with the help of these classes you can create custom designs.

Why do we use Tailwind in our Projects?

Tailwind is designed to be component-friendly. It is much easier to write and read and also easier to separate the site’s elements into small components and not to use objects and classes in the components. It is easier to maintain and for testing purposes because we have to write the CSS on an inline basis. Custom styling can be provided to the components with the help of the Tailwind CSS framework. The framework is highly customizable because we have to use the file tailwind.config.js file in our project.

The Tailwind CSS is used for the default mobile-first approach. With the help of this framework, we can develop a complex responsive layout freely.

How to setup Tailwind with the project:

Now we discuss how we integrate Tailwind with the project. First, we create a new project from scratch. Create a new project folder by using this command run this command in your terminal.

Now go into the newly created project folder (tailwind_demo)

Now we initialize the node module in our project and create package.json with help of this command

This command enables the Node.js package manager to manage the dependency in our project. The first dependency which we use in our project is the tailwind package. We can install the tailwind package by the following command:

From this command we make sure tailwind is downloaded and saved in the node_module folder and dependency is added into the package.Json file.

Now a step comes when we add the tailwind to the project’s CSS. This is done by creating the new file css/style.css and importing the @tailwind base, @tailwind components, @ tailwind utilities.

Create the Tailwind config file:

To complete the tailwind setup we have to create the new initial configuration file by following the command.

This command creates the new file named tailwind.config.js with the following content inside.

How to process CSS with Tailwind:

For the processing of CSS file Tailwind require’s the build process. To set up the build process there is one option which is PostCSS. PostCSS is the tool that transforms the CSS with javascript. Tailwind is also working with plugins and it is easy to perform the tailwindcss with the tailwind postcss plugin.

Now we have to install PostCSS and autoprefixer by using the following command

After successfully installing the plugin now we have to create the postcss config file in our project directory.

Insert the following content in the newly created file.

Now we have to specify that the postcss process should perform CSS processing with the tailwind and with the auto fixer.

Insert the following content in the package.json file.

Here, we have to execute the script with the help of the following command.

Using with HTML file:

First, we have to create the new file named Index.html and in the following HTML code.

Example:

How to style a button with the tailwind.

 

Leave a Reply