Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind CSS is not working in Vite + React

I created a React application using Vite and used the documentation provided here to install Tailwind: Tailwind CSS Installation Guide.

However, it's not picking up any of the Tailwind styles.

tailwind.config.cjs

/** @type {import('tailwindcss').Config} */
module.exports = {
  content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"],
  theme: {
    extend: {},
  },
  plugins: [],
};

index.css

@tailwind base;
@tailwind components;
@tailwind utilities;

main.tsx

import React from "react";
import ReactDOM from "react-dom/client";
import { RouterProvider } from "react-router-dom";
import { router } from "./router";
import "./index.css";

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <React.StrictMode>
    <RouterProvider router={router} />
  </React.StrictMode>
);

The only dependency I have installed is react-router-dom.

How can I fix this?

like image 572
Prajul Aaditya Avatar asked Dec 01 '25 09:12

Prajul Aaditya


2 Answers

Here are the Changes I made in vite.config.js and it worked

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from 'tailwindcss'

export default defineConfig({
  plugins: [react()],
  css: {
    postcss: {
      plugins: [tailwindcss()],
    },
  }
})
like image 148
Vaishnavi Rama Shanmugam Avatar answered Dec 03 '25 01:12

Vaishnavi Rama Shanmugam


If you have installed postcss and autoprefixer (as outlined in step #2 here: https://v3.tailwindcss.com/docs/guides/vite), you should see both libraries in the "devDependencies" section of your package.json. If they are installed, you will need a postcss.config.cjs file in the root of your project which contains the following:

module.exports = {
  plugins: [require("tailwindcss"), require("autoprefixer")],
};
like image 34
Ed Lucas Avatar answered Dec 03 '25 00:12

Ed Lucas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!