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

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
🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ† āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

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
🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ† āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

Step 3: Create a Tailwind Config File

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

npx tailwindcss init -p
🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ† āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

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}",
],
🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ† āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
  • 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}",
],
🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ† āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

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;
🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ” ðŸ† āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”

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

Top comments (14)

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
gwepura profile image
Gwepura •

You are a heaven-sent! I was about to close my laptop and go to sleepðŸĪĢðŸĪĢ

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
myogeshchavan97 profile image
Yogesh Chavan •

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

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
abdrzqsalihu profile image
Abdulrazaq Salihu •

Thanks a lot man, this was beyond helpful.

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
myogeshchavan97 profile image
Yogesh Chavan •

Glad you found it helpful. Thank you🙏

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
keyuan_dy_df479b6ddb48984 profile image
keyuan DY •

cool. thanks

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
myogeshchavan97 profile image
Yogesh Chavan •

Glad you found it helpful. Thank you🙏

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
odjama_white profile image
Saestwo •

The compatibility issue is pretty stressful, thank you!

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
myogeshchavan97 profile image
Yogesh Chavan •

That's so true. Thanks for reading🙏

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
masadamsahid profile image
Maulana Adam Sahid •

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

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
myogeshchavan97 profile image
Yogesh Chavan •

Haha. Thank you🙏

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
samadhee_samarasinghe profile image
Samadhee Samarasinghe •

Thank you so much. This was really helpful.

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
myogeshchavan97 profile image
Yogesh Chavan •

Glad to hear that. Thank you🙏

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
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.

🏆 āļĒāļ­āļ”āļ™āļīāļĒāļĄ: myogeshchavan/lost in transition how to downgrade to tailwind css v in nextjs and react kl - āļŠāļĢāļļāļ›āļ”āļĢāļēāļĄāđˆāļēāļĨāđˆāļēāļŠāļļāļ”
 
myogeshchavan97 profile image
Yogesh Chavan • • Edited

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