DEV Community

Cover image for Tailwind CSS v4: Quick Guide ๐Ÿš€
Utkarsh Web
Utkarsh Web

Posted on

1 1 1 1

Tailwind CSS v4: Quick Guide ๐Ÿš€

Why Tailwind v4.0 is a Game-Changer ๐Ÿ”ฅ

Hey devs! Tailwind CSS v4.0 is not just an update. It reshapes the way we write CSS. Forget about complex configuring or slow builds. This version introduces a greater focus on speed, simplicity, and modern web standards.
Key Superpowers of Tailwind v4.0

  • ๐Ÿš€ Lightning-Fast Performance
  • ๐Ÿ’ป Zero-Config Setup
  • ๐ŸŽจ Native CSS Features

Getting Started: Installation Magic โœจ

Quick install for React/Next.js projects

npm install tailwindcss@latest postcss
Enter fullscreen mode Exit fullscreen mode

Configuration: Goodbye JavaScript, Hello CSS!

/* New CSS-first configuration */
@import "tailwindcss";

@theme {
  --color-primary: oklch(0.72 0.19 244.08);
  --font-body: 'Inter', sans-serif;
  --breakpoint-custom: 1440px;
}
Enter fullscreen mode Exit fullscreen mode

React & Next.js Integration: Stupid Simple

Vite Setup


// vite.config.js
export default {
  plugins: [
    tailwindcss(), 
    react()
  ]
}

Enter fullscreen mode Exit fullscreen mode

Next.js Configuration

// next.config.js
module.exports = {
  experimental: {
    tailwindcss: {
      version: '4.0'
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Pro Migration Tips ๐Ÿ’ก

  1. Backup Your Project: Always create a git branch

  2. Test Thoroughly: Check responsive designs

  3. Use Migration Tool:

npx @tailwindcss/upgrade
Enter fullscreen mode Exit fullscreen mode

Common Gotchas to Watch ๐Ÿšจ

  • Colour space changes
  • Removed deprecated utilities
  • New breakpoint syntax

Performance Benchmark ๐Ÿ“Š

โœ… Build Time:

  • v3: ~3-5 seconds
  • v4: ~0.5-1 seconds

โœ… Bundle Size:

  • Reduced by 35%

Real-World Example: Responsive Card

function DevCard() {
  return (
    <div className="
      bg-primary 
      p-4 
      rounded-lg 
      hover:scale-105 
      transition-transform
    ">
      Developer Profile
    </div>
  )
}
Enter fullscreen mode Exit fullscreen mode

When to Upgrade? ๐Ÿค”

Upgrade Immediately If:

  • Building new projects
  • Performance is critical
  • Want modern CSS features

Wait If:

  • Mission-critical legacy project
  • Complex custom configurations

Learning Resources ๐Ÿ“š

Official Tailwind Docs
Migration Guide
Community Discord

Final Thoughts ๐ŸŒŸ

Tailwind v4.0 is not just a change in version; it is a declaration on how modern web development should be: fast, intuitive, and powerful. Pro tip: Read it only after you have tried to apply it to a small project.

About the Author

Utkarsh Tiwari is passionate about making web development simpler and faster. Follow for more cutting-edge tech insights! #TailwindCSS #WebDev #Frontend #React #Performance

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadogโ€™s testing tunnel.

Download The Guide

Top comments (13)

Collapse
 
maxart2501 profile image
Massimo Artizzu โ€ข
Comment hidden by post author
Collapse
 
utkarshthedev profile image
Utkarsh Web โ€ข

Ah yes, because writing raw CSS with infinite .div > .div > .div ** nesting is so much **faster than using utility classes. Nothing speeds up development like scrolling through a 5,000-line stylesheet just to find why that one button wonโ€™t center.

And sure, [&>.has-[:checked]]:h-3.5] **looks complexโ€”until you realize it **saves you from writing five extra lines of CSS, a !important war, and a therapy session over specificity issues.

As for โ€˜things you just canโ€™t do with Tailwindโ€™โ€”I mean, you could still write custom CSS, but I get it, that's a radical concept for someone who thinks Tailwind is adding 30 extra packages when itโ€™s literally just a PostCSS plugin.

But hey, if you love reinventing the wheel with inline styles and wondering why your CSS file is bigger than your entire app, more power to you!

Collapse
 
maxart2501 profile image
Massimo Artizzu โ€ข โ€ข Edited

Ah yes, because writing raw CSS with infinite .div > .div > .div ** nesting is so much **faster than using utility classes. Nothing speeds up development like scrolling through a 5,000-line stylesheet just to find why that one button wonโ€™t center.

Ask yourself why you're dealing with a 5kLOC stylesheet.

If you're dealing with a legacy project, then sure, throw Tailwind at it. It's already a disaster anyway.

But if you ended up creating such mess... Well, that's entirely on you and your inability to organize your styles. If you think Tailwind will solve this, you're only deluding yourself: your style declarations will alway be a mess.

My stylesheets rarely go over 100 LOCs. Most are around 50-60 lines. The cascade is never a problem. Thus I don't care much about the specificity of my selectors, but it's usually 0.0.1 - not even 0.1.0. When it goes over, it's because of attributes and pseudo-classes. I very rarely use classes, and so I rarely get to name anything. Because if I have trouble with naming things, then it's a sign I have no idea of what I'm doing. And it's just something that doesn't happen to me, period.

Ask me how.

And if you're wondering, yes, I worked on large projects. And I created UI libraries used by hundreds of developers. I just happen to have method.

And sure, [&>.has-[:checked]]:h-3.5] **looks complexโ€”until you realize it **saves you from writing five extra lines of CSS

Oh yes, those five extra lines of well-readable style declarations will be the death of me... It's not like the IDE and AI tools will help me in 2025, no...

Some wise man once said:

"Programs are meant to be read by humans and only incidentally for computers to execute."

(No, it's not Donald Knuth.) Point is: if I wanted to write my styles like that, I'd write all my code in Brainfuck. Tailwind has created a whole arbitrary language to style that's essentially write-only just like a regular expression: you can debug and fix a regular expression, but it's much harder than doing it with regular JavaScript.

Don't get me wrong: I love regular expressions. But I still loathe Tailwind. Because regular expressions don't bloat with code and I use them for very specific purposes.

a !important war

It's funny because the last !important war I had to fight was because of Tailwind! Because yes, Tailwind also breaks the "golden rule" of utility classes to all have specificty 0.1.0. I had to use !my-4 to cut the crap short.

At least Bootstrap is true to that principle.

Oh yeah, I could've used @layer... if only Tailwind didn't break the ability to use it! Meaning that not only Tailwind has caused me a specificity issue, but it also prevented everyone to effectively fix it!

itโ€™s literally just a PostCSS plugin.

And that's the worst delusion of all.

Tell me if tailwind-merge is a PostCSS plugin. If clsx is. If the IDE plugins you're using for handling the mess in your code are for PostCSS. Sure, you can do without them... if you want to make a hell of your life.

I usually don't use PostCSS, period. If I want to get fancy, good old SASS gives me all that I need.

But hey, if you love reinventing the wheel with inline styles and wondering why your CSS file is bigger than your entire app, more power to you!

And less to you, apparently, if you think the alternative is... inline styles?!

Now bring me a project where the stylesheet is bigger than the whole app. Come on, I challenge you.

Oh wait, I actually have some: it's those projects that came to production with the entirety of Tailwind because they didn't set up the build step correctly. Ironic, isn't it? But it's something that has happened.

And PSA: performance-wise, stylesheet are never the problem. Parsing is way faster than JavaScript. Compression is better than HTML and JavaScript. And browsers cache them aggressively.

On the converse, Tailwind taints my markup to the point where what I save on .css files, I spend twice on the .html, that cannot be as easily cached. Great saves, huh?

But hey, if you want to believe that Tailwind still makes a shred of sense... more power to you.

Thread Thread
 
utkarshthedev profile image
Utkarsh Web โ€ข

Alright, listen upโ€”if you're still clinging to a 5kLOC stylesheet like it's some badge of honor, maybe it's time to clean up your act instead of blaming Tailwind. Let's break it down with a few facts:

** Organization Over Quantity:**
A 5kLOC stylesheet isnโ€™t Tailwindโ€™s doingโ€”itโ€™s a monument to disorganized coding. Tailwind is designed to keep your custom CSS lean (often around 50โ€“100 lines). If your styles scream 'spaghetti mess,' maybe the problem is less about the framework and more about your approach.

** Specificity Simplified:**
Sure, some of Tailwind's utility classes might look odd at first glance, but they're crafted to save you from writing repetitive, hard-to-maintain CSS. If you're getting into endless specificity battles, itโ€™s not Tailwind's faultโ€”itโ€™s a sign that your current methods are out of date. Tailwind helps keep things predictable, not a playground for your naming nightmares.

** HTML Bloat vs. CSS Efficiency:**
Worried about bloated HTML? Modern build tools like PurgeCSS and Tailwindโ€™s JIT mode cut out unused classes like a pro. While you might moan about HTML size, browsers parse CSS lightning fast and cache it aggressively. So unless your projectโ€™s performance is suffering, your gripe might be more about personal taste than actual issues.

** Utility-First Benefits:**

Tailwind isnโ€™t just 'a PostCSS plugin'โ€”it's a full utility-first framework that pushes for consistency and rapid development. If you're still stuck in the era of manually writing endless lines of CSS, perhaps you should consider that the world of web development has moved on. Tailwind's prosโ€”speed, maintainability, and a scalable design systemโ€”often outweigh its cons, especially when you set it up correctly.
Enter fullscreen mode Exit fullscreen mode

Tailwind forces you to adopt better practices. If your codebase looks like a mess, it's more likely your own doing rather than a failing of the framework. Instead of railing against Tailwind, maybe take a look at your coding habits and see what really needs fixing. Time to evolve, my friend.

Thread Thread
 
maxart2501 profile image
Massimo Artizzu โ€ข

Oh wow. Now you resorted to ChatGPT answers, since you just don't have arguments?

Because I can't explain how unhinged this is from what I actually said.

Bye bye.

Thread Thread
 
utkarshthedev profile image
Utkarsh Web โ€ข

Bro, you're just trying to twist the narrative here. The reality is simpleโ€”Tailwind is better than writing plain CSS in a stylesheet, and if it wasnโ€™t, it wouldnโ€™t be widely adopted by so many developers and major projects. It exists because it solves real problems. If youโ€™re struggling with it, maybe the issue isnโ€™t Tailwind but how youโ€™re approaching it. Try building the same project with Tailwind and then with traditional CSSโ€”youโ€™ll see the difference firsthand. Sometimes, it's just about shifting your perspective instead of resisting progress.

Thread Thread
 
maxart2501 profile image
Massimo Artizzu โ€ข

Tailwind is better than writing plain CSS in a stylesheet, and if it wasnโ€™t, it wouldnโ€™t be widely adopted by so many developers and major projects.

This sounds very much like: "Eat sh*t! Billions of flies cannot be wrong!"
That's the worst argument ever. It means that if something reaches some critical mass, it will never be surpassed.
But that's not how the industry works, otherwise we'd all be still working with PHP and jQuery (much respect for all who still do).
Nah. Hype-driven solutions are not for me. But coming from you, I'm not surprised, because you're clearly part of the flock.

It exists because it solves real problems.

Like, avoiding to learn CSS properly? Pass.

From my experience, Tailwind has never solved a single problem. All it could do is offering short-term gains in exchange for medium- and long-term disasters.

I youโ€™re struggling with it, maybe the issue isnโ€™t Tailwind but how youโ€™re approaching it.

I don't struggle with Tailwind. I know enough CSS that Tailwind couldn't be anything more than a nuisance. I just consider it a detrimental layer over what I could do just fine.

Try building the same project with Tailwind and then with traditional CSSโ€”youโ€™ll see the difference firsthand.

And you think I don't already? That's exactly why I loathe Tailwind.

Sometimes, it's just about shifting your perspective instead of resisting progress.

Tailwind isn't a specified standard. It will be left in the dust, while CSS will progress on. I stay with the latter.

Thread Thread
 
utkarshthedev profile image
Utkarsh Web โ€ข

Alright, listen up:

Your argument is nothing more than a tired rant from someone stuck in the past. Let's set the record straight:

Popularity โ‰  Mindless Hype:

Claiming Tailwind's widespread use means "billions of flies cannot be wrong" is lazy. Its adoption is based on real benefitsโ€”speed, maintainability, and consistencyโ€”not on a mindless bandwagon. Dismissing it as mere hype only shows your inability to see its

CSS Mastery Isnโ€™t a Prerequisite for Efficiency:

Suggesting that Tailwind exists just to help people avoid learning CSS properly is laughable. Top developers use Tailwind because it streamlines their workflow and eliminates repetitive tasks. If youโ€™re so attached to writing endless lines of CSS, then maybe itโ€™s your approach thatโ€™s outdatedโ€”not Tailwindโ€™s fault.

Short-Term Gains vs. Long-Term Disasters:

Your claim that Tailwind offers only short-term gains and leads to long-term disasters is baseless. Countless projects thrive with Tailwind because it provides a scalable, maintainable framework. If you haven't experienced these benefits firsthand, that's on your narrow perspective, not on the framework itself.

Refusal to Adapt:

You dismiss Tailwind outright because it doesn't fit your old-school standards, yet the industry evolves by embracing tools that genuinely improve productivity. Clinging to your โ€œsuperiorโ€ traditional CSS is not progressโ€”itโ€™s stagnation.

Remember: "Arguing with a fool means there are two fools in the room." Your rant doesn't hold water; it just proves that you're the one refusing to evolve. Instead of railing against innovation, try opening your mind to modern practicesโ€”otherwise, you'll always be left in the dust.

Thread Thread
 
maxart2501 profile image
Massimo Artizzu โ€ข

Dude, stop copying responses from ChatGPT: it's frankly embarassing for you. Just admit you don't know how to reply.

Thread Thread
 
utkarshthedev profile image
Utkarsh Web โ€ข

Bro, I copied that from ChatGPTโ€”like everyone doesโ€”so why should I waste time on your weak, biased arguments? I already dropped the quote:

"Arguing with a fool means there are two in the room."

I'm not going to argue with someone stuck in outdated thinking. Developers focus on productivity and efficiency, not endless debates about design fluff. So, unless you're ready to upgrade your mindset, I'm done wasting my time here.

Thread Thread
 
maxart2501 profile image
Massimo Artizzu โ€ข

Bro, I copied that from ChatGPTโ€”like everyone does

And you're accusing me of bias...
No, not everyone copies from ChatGPT. That qualifies you as a developer: someone who can't express a reasoning outside the prompted response of a probabilistic machine. I think it's pretty clear who's the fool here.

Thread Thread
 
utkarshthedev profile image
Utkarsh Web โ€ข

Look, it's clear you're stuck in the past. If you weren't so biased, you'd see that Tailwind and AI boost productivity and efficiencyโ€”real tools that help get work done faster. Instead, you cling to old-school CSS like it's some kind of badge of honor, ignoring how much smarter modern development is.

Letโ€™s be clear: if you don't use AI, you'll soon be replaced by someone who does. And if you truly cared about productivity, you'd look up how Tailwind makes styling a breeze. Instead, you're busy arguing about things that don't matter because you're too attached to your outdated methods.

Remember: "Arguing with a fool means there are two in the room." I'm not wasting any more time on this debate. While I and many other developers move forward with tools that matter, you'll keep spending hours writing endless CSS. Carry on with your old waysโ€”I'll be here building the future.

Thread Thread
 
maxart2501 profile image
Massimo Artizzu โ€ข โ€ข Edited

๐Ÿฅฑ

Wake me up when you have something to say.
It's 25 years that utility classes exist. We've already seen soar and fade Bootstrap, Tachyons, Basscss. And you say I'm stuck in the past...
Tailwind is only the next in line.

Some comments have been hidden by the post's author - find out more

Sentry image

See why 4M developers consider Sentry, โ€œnot bad.โ€

Fixing code doesnโ€™t have to be the worst part of your day. Learn how Sentry can help.

Learn more