What's New In Tailwind CSS v4.0 And How To Migrate To It
Tailwind CSS v4.0 is here! and introduces some significant changes that improve performance and refine the developer experience.
There’s a huge amount to cover, but let’s take a look over some of the key changes that will revolutionise the way you write CSS.
It’s Faster!
#The newest version of Tailwind CSS, version 4.0 utilises the Oxide engine which incorporates Lightning CSS. As with most modern tooling, the speed gains of rust are being leveraged to introduce extremely favourable developer experience gains.
Rust allows us to utilise multi-threading and parallelisation to execute computation quickly. Its main goal is to minify a huge amount of CSS and to do so quickly.
v3.4 | v4.0 | Improvement | |
---|---|---|---|
Full build | 378ms | 100ms | 3.78x |
Incremental rebuild with new CSS | 44ms | 5ms | 8.8x |
Incremental rebuild with no new CSS | 35ms | 192µs | 182x |
Tailwind is now ESM Only
#One of the biggest changes in v4.0 is that Tailwind is now exclusively ESM (ECMAScript Modules). This means Tailwind must be imported using import
instead of require
.
This aligns with modern JavaScript practices and improves compatibility with newer tooling.
Example of how to import Tailwind in ESM:
_10// tailwind.config.mjs <-- notice the .mjs extension for ESM support_10import { defineConfig } from 'tailwindcss';_10_10export default defineConfig({_10 theme: {_10 extend: {},_10 },_10 plugins: [],_10});
If you're still using CommonJS, you’ll need to migrate to ESM. More on that in the migration section below.
New API for Custom Utilities
#The @utility
API replaces the older @layer utilities
, providing a clearer and more structured way to define custom utilities. Here are additional examples illustrating this transition:
_10@utility margin-auto {_10 margin: auto;_10}_10_10@utility flex-center {_10 display: flex;_10 justify-content: center;_10 align-items: center;_10}
These new declarations enable more explicit management of utility classes in your projects.
_10@utility box {_10 padding: 2rem;_10}
Then in your HTML
_10<div class="box" />
Built-in Container Query Support
#All major browsers today support container queries. Previously, you had to install @tailwindcss/container-queries
plugin to get this done.
Now you can do it natively with @container
directive.
It has also added support for max-width container queries using the new @max-*
variant. This can be used to stack these variants to define container query ranges.
_10<div class="@container">_10 <div class="flex @min-md:@max-xl:hidden" />_10</div>
Info
Interested to understand more about the power of container queries? Find out more: Harnessing CSS Container Queries For Advanced Responsive Design
No more Support for Node.js 14
#Tailwind CSS v4.0 now requires Node.js 16 or later. If you’re using an older version, you’ll need to upgrade your Node.js environment. You can chek your current version by running:
_10node -v
If you need to update, install the latest version via NVM:
_10nvm install 18_10nvm use 18
or if you’re using volta:
_10nvm install node@18_10nvm pin node@18
Smaller CSS Output with Automatic Purging
#Tailwind CSS v4.0 automatically removes unused styles by default. This means you no longer need to configure purge
or content
manually. This results in significantly smaller CSS files, making your apps faster.
Tailwind v3.x
_10module.exports = {_10 content: ['./src/**/*.{js,ts,jsx,tsx,html}'],_10 theme: {_10 extend: {},_10 },_10};
Tailwind v4.0
_10export default {_10 theme: {_10 extend: {},_10 },_10};
The content
configuration is inferred automatically based on your project's file structure, reducing boilerplate configuration.
CSS-First Configuration
#Tailwind v4.0 introduces a CSS-first approach, allowing developers to configure design tokens, breakpoints, and more directly in the CSS file instead of the tailwind.config.js
. This simplifies the setup and makes the workflow more intuitive.
Tailwind v4.0 introduces design tokens as CSS variables, allowing for greater runtime flexibility. Colors, fonts, and breakpoints can now be defined as CSS variables and dynamically referenced across the project.
_10@import "tailwindcss";_10_10@theme {_10 --font-display: "Poppins", "sans-serif";_10 --breakpoint-3xl: 1920px;_10 --color-avocado-100: oklch(0.99 0 0);_10 --color-avocado-200: oklch(0.98 0.04 113.22);_10}
Tailwind v4.0 introduces design tokens as CSS variables, allowing for greater runtime flexibility. Colors, fonts, and breakpoints can now be defined as CSS variables and dynamically referenced across the project.
_10:root {_10 --font-display: "Satoshi", "sans-serif";_10 --color-avocado-100: oklch(0.99 0 0);_10}
Additionally, native CSS cascade layers are now supported, giving developers greater control over the order of styles and ensuring that higher layers don’t unintentionally override lower ones. This leads to more predictable and organised CSS output
New Default Theme Updates
#Tailwind v4.0 introduces new defaults for colors, spacing, and shadows, making designs look more modern out of the box.
For example:
_10/* New default shadows */_10shadow-sm: 0px 1px 2px rgba(0, 0, 0, 0.05);_10shadow-md: 0px 4px 6px rgba(0, 0, 0, 0.1);
If you rely on Tailwind’s default styles heavily, you might notice subtle visual differences when upgrading.
Simplified CSS imports
With the updates to Tailwind v4.0, we only need to import one dependency.
Tailwind v3.x
_10@tailwind base;_10@tailwind components;_10@tailwind utilities;
Tailwind v4.0
_10@import "tailwindcss";
How to Migrate to Tailwind CSS v4.0
#If you’re currently using Tailwind v3.x and want to upgrade, follow these steps to ensure a smooth transition.
A Migration Tool to Simplify the Transition
Tailwind CSS offers an upgrade tool that automates most of the required changes. It requires Node.js 20 or later, so ensure your environment is up to date before running it.
Tip
As always it’s great practice to understand what helpful shortcuts are doing in our code so we can verify it’s doing the right thing for our case. Run this tool in a new Git branch to easily compare changes and be sure to check everything works as expected.
_10$ npx @tailwindcss/upgrade@next
This tool will update your dependencies, migrate your configuration files, and adapt your template files.
The Manual Approach
Upgrade Tailwind
Run the following command to update Tailwind to the latest version:
_10npm install -D tailwindcss@latest
or
_10yarn add -D tailwindcss@latest
Update Your tailwind.config.js
Rename tailwind.config.js
to tailwind.config.mjs
to support ESM by converting any require()
imports to import
.
If your tailwind.config.js
includes a content
property, you can remove it, If you're using standalone mode, remove @tailwind base;
from your CSS.
Tailwind v3.x
_10const { defineConfig } = require('tailwindcss');_10_10module.exports = defineConfig({_10 content: ['/src/**/*.tsx']_10 theme: {_10 extend: {},_10 },_10});
Tailwind v4.0
_10import { defineConfig } from 'tailwindcss';_10_10export default defineConfig({_10 theme: {_10 extend: {},_10 },_10})
To update the css you will need to make the following changes.
Tailwind v3.x
_10@tailwind base;_10@tailwind components;_10@tailwind utilities;
Tailwind v4.0
_10@import "tailwindcss";
Test Your Application
Run your dev server and check for any issues:
_10npm run dev
Conclusion
#Tailwind CSS v4.0 brings tonnes of key simplifications and performance improvements, making the framework even more flexible helping you to write code quicker. While some adjustments are required, the migration process is straightforward, especially with the provided tools.
To find out more about all the changes in Tailwind v4.0 head over to the tailwind docs.
Halpy coding,
CSS
Thanks alot for your feedback!
The insights you share really help me with improving the quality of the content here.
If there's anything you would like to add, please send a message to:
[email protected]Was this article this helpful?

About the author
Danny Engineering
A software engineer with a strong belief in human-centric design and driven by a deep empathy for users. Combining the latest technology with human values to build a better, more connected world.