Hopp til innhold
← ALL POSTS

Configure your React + Vite Application for Tailwind CSS

Learn how to set up a React + Vite application with Tailwind CSS, allowing for flexible and efficient design using utility classes for your web projects.

ABDUS SAYEF REYADH2 MIN READ

Introduction

Tailwind is a sizable collection of tiny CSS utility classes for rapidly and reliably creating attractive websites. Frameworks like Antd, Bootstrap and Material Design have high-level components like buttons, cards, grids, menus and forms to create different components, Tailwind provides a more practical approach by giving you utility classes that can be used to create components similar to these. This approach gives you significantly more creative freedom than other CSS frameworks while still sticking to a design structure that you wouldn’t obtain with pure CSS.[Ref]

Let’s start with creating aReact typescript application with Vite naming it tailwind-client, if you have an existing project start from the Tailwind Configuration Setup section.

Tailwind CSS in Action

Initial Setup

npm create vite@latest tailwind-client — –template react-ts

After creating the react application, install all the dependencies using the following command.

cd tailwind-client

npm install

Tailwind Configuration Setup

Now inside the application folder, we have to install tailwindcss along with its corresponding dependencies postcss and autoprefixerusing the following command and later generate both tailwind.config.js and postcss.config.js configuration files.

npm install -D tailwindcss postcss autoprefixernpx tailwindcss init -p

Now configure the tailwind.config.js and index.css(in src folder) file in the following way.

**tailwind.config.js

**

/** @type {import(‘tailwindcss’).Config} */

module.exports = {

  content: [“./src/**/*.{js,jsx,ts,tsx}”],

  theme: {

    extend: {},

  },

  plugins: [],

};

src/index.css

Append the following lines at the top of the file index.css

@tailwind base;

@tailwind components;

@tailwind utilities;

Yay!! We are all set up to start exploring tailwindcss. If you are using VS Code, consider installing theTailwind CSS IntelliSense Extension to get inline suggestions while development.

NEWSLETTER

One engineering letter a month

New writing from our engineers, no marketing filler.

[ ONE CONVERSATION AWAY ]

Rather ask an engineer than read another post?

Thirty minutes, no sales script. Bring the problem you are actually stuck on and we will tell you honestly whether we are the right partner for it.