DEV Community

Cover image for Lost in Transition: How to Downgrade to Tailwind CSS v3 in Next.js And React
Yogesh Chavan
Yogesh Chavan

Posted on • Edited on

11 1 1 3 1

Lost in Transition: How to Downgrade to Tailwind CSS v3 in Next.js And React

The recent release of Tailwind CSS v4 has brought about significant changes.

One of the most noticeable differences is the absence of a tailwind.config.js file when creating a new Next.js application. This has left many developers confused, especially when trying to follow tutorials or videos that use Tailwind CSS v3.

While mentoring on Codementor, I have seen many developers struggling with this issue.

If you're one of them, don't worry! Here's a step-by-step guide on how to use Tailwind CSS v3 in your Next.js and React.js project.

Why Downgrade to Tailwind CSS v3?

While Tailwind CSS v4 offers many exciting features, some developers might prefer to stick with v3 for various reasons, such as compatibility issues or familiarity with existing projects. Whatever your reason, downgrading is straightforward.

Steps to Downgrade to Tailwind CSS v3

Step 1: Uninstall Tailwind CSS v4

First, you need to uninstall the installed Tailwind CSS v4. You can do this by running the following command in your terminal:

npm uninstall tailwindcss
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Tailwind CSS v3

Next, install Tailwind CSS v3 along with other necessary dependencies using the following command:

npm install -D tailwindcss@3.4.17 postcss autoprefixer
Enter fullscreen mode Exit fullscreen mode

Step 3: Create a Tailwind Config File

Now, create a tailwind.config.js file by executing this command:

npx tailwindcss init -p
Enter fullscreen mode Exit fullscreen mode

Step 4: Configure the Content Array

Open the newly created tailwind.config.js file and update the content array to include your project's paths.

  • For Next.js Projects: Replace the existing content with the following code:
content: [
  "./pages/**/*.{js,ts,jsx,tsx,mdx}",
  "./components/**/*.{js,ts,jsx,tsx,mdx}",
  "./app/**/*.{js,ts,jsx,tsx,mdx}",
],
Enter fullscreen mode Exit fullscreen mode
  • For Vite + React.js Projects: Use the following configuration instead:
content: [
  "./pages/**/*.{js,ts,jsx,tsx,mdx}",
  "./components/**/*.{js,ts,jsx,tsx,mdx}",
  "./app/**/*.{js,ts,jsx,tsx,mdx}",
  "./src/**/*.{js,ts,jsx,tsx,mdx}",
],
Enter fullscreen mode Exit fullscreen mode

Step 5: Update Your Global CSS File

Finally, add the following lines to your main global.css or index.css file:

@tailwind base;
@tailwind components;
@tailwind utilities;
Enter fullscreen mode Exit fullscreen mode

You're Done!

By following these steps, you should now have Tailwind CSS v3 up and running in your Next.js and React.js project.

This setup will allow you to continue using the features and configurations you're familiar with from v3, making it easier to follow older tutorials or maintain existing projects.

Happy coding!

Connect With Me

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

Top comments (12)

Collapse
 
gwepura profile image
Gwepura

You are a heaven-sent! I was about to close my laptop and go to sleep🤣🤣

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

Haha. Glad to hear it was helpful to you. Thank you🙏

Collapse
 
odjama_white profile image
Saestwo

The compatibility issue is pretty stressful, thank you!

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

That's so true. Thanks for reading🙏

Collapse
 
keyuan_dy_df479b6ddb48984 profile image
keyuan DY

cool. thanks

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

Glad you found it helpful. Thank you🙏

Collapse
 
abdrzqsalihu profile image
Abdulrazaq Salihu

Thanks a lot man, this was beyond helpful.

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

Glad you found it helpful. Thank you🙏

Collapse
 
dishantgusain profile image
Dishant Gusain • Edited

Thank you for this post, I was going insane without tailwind.config file. Created account just for this comment.

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan • Edited

haha. You're not alone. Glad you found it helpful. Thanks for reading!

Collapse
 
masadamsahid profile image
Maulana Adam Sahid

TailwindCSS's CSS config file is bad. But you are best 😁

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

Haha. Thank you🙏

👋 Kindness is contagious

If you found this post helpful, please leave a ❤️ or a friendly comment below!

Okay