How to upgrade an Astro JS project from Tailwind CSS v3 to Tailwind CSS v4
Published and written on
Oct 22 2024 by Michael Andreuzza
It’s been a while since the Tailwind Labs team anounced the release of Tailwind CSS v4, so let’s take a look on how yto upgrade and Astro JS project to Tailwind CSS v4 ( Alpha ). At least, with what we know so far.
What do we know so far
Tailwind CSS 4.0 offers big improvements for faster, easier web development with the new Oxide engine.
Tailwind CSS 4.0 brings several improvements for faster, more flexible development. It emphasizes a CSS-first approach, simplifying design system management without relying on JavaScript. With composable variants, you can easily combine styles, and automatic content detection applies styles without manual setup.
The new Oxide engine, built with Rust, improves performance with faster compilation times. Tailwind also supports modern features like cascade layers and container queries, while the integration of Lightning CSS simplifies setup and reduces complexity.
Let’s upgrade
Disclaimer:This is how I personally approach it, if you like or want to do it in different steps, go ahead and do so
1. First of all we are going to remove the @astrojs/tailwind package because it’s not compatible with Tailwind CSS v4.
npm uninstall @astrojs/tailwind
2. Let’s install Tailwind CSS and vite official plugin:
Now that we have import Tailwind, we might have to make sure to import the plugins we are using, if we are.
On the case of the forms and typography plugins we are goidn to do like this.
Just like how we defined them on the tailwind.config.js file, but only as one line for each import. You can now translate the tailwind.config.js to css and after that remove the file.
From now on, we start using Tailwind CSS on our project.
Hope this helps, and you can get your project upgrade. But, hey, watch out because it’s on alpha, and there’s many changes coming up.
For example, 2xl:width might be deprecated, and we might have to use 2xl:max-w-[var(--breakpoint-2xl)] instead, like Admam Wathan said on this comment
/Michael Andreuzza
Did you like this post? Please share it with your friends!
Astro v5
/
Tailwind CSS v4
One price. Lifetime access.
34 Premium Astro Templates
All Future Templates Included
Unlimited Projects · Lifetime License
Fastest product ever paid. Keep up the great work — Raf, RafWorks
The value in this is incredible. Every single one of the themes is a piece of art — Dan Mindru, Clobbr
Big fan of your themes. They're well-organized, look clean, and are fast — Keving Focke, Developer
Michael has been dropping some amazing premium themes for Astro lately — Fred Schott, Astro