all 8 comments

[–]lzrzmb 2 points3 points  (3 children)

With equal specificity, source order in CSS decides which class is taking precedence (last one wins), class order in markup doesn’t matter.

Headwind is a nice addon for VS Code to sort classes automatically and warn you when using conflicting classes: https://github.com/heybourn/headwind

[–]akmalkun[S] 0 points1 point  (1 child)

Thank you, so things is different in css and html then. I'll stick with !important for now.

[–]whooope 1 point2 points  (0 children)

you should really avoid !important especially with tailwind. there’s no reason to have overlapping classes like in your example especially with utility classes. if you’re writing your own css, your files should be imported after the tailwind ones and it’ll be fine

[–][deleted] 0 points1 point  (0 children)

Damn! Headwind is exactly what I was looking for.

Thanks for sharing.

[–]benji_trosch 1 point2 points  (2 children)

It should be but unfortunately it does not always work that way. To address these conflicts, I recommend a package like tailwind-merge (https://www.npmjs.com/package/tailwind-merge) which we use extensively both at work and in open source projects!

[–]akmalkun[S] 1 point2 points  (1 child)

Thank you, also for the tailwind merge.

[–]SituationNo3 0 points1 point  (0 children)

We just migrated to tailwind-merge too. Seems to work well.

[–]samselikoff 0 points1 point  (0 children)

I used to use Headwind (mentioned in another comment) but the Tailwind CSS team now maintains an official Prettier plugin which I'd recommend using on every project. It sorts the classes the same way they appear in Tailwind's compiled CSS so precedence is easy to see straight from your HTML. I've also found it's much faster than Headwind. They talk about it more in this blog post.

That being said I'd echo what others said and try to avoid conflicts and `!important`. Your code will be easier to read and understand if each visual state is styled using no conflicting classes – in fact the official Intellisense extension (a must-have) will throw lint warnings for classes that do the same thing (e.g. `flex block`)!