Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tailwind CSS v4 support #513

Closed
dcastil opened this issue Jan 16, 2025 · 6 comments · Fixed by #518
Closed

Tailwind CSS v4 support #513

dcastil opened this issue Jan 16, 2025 · 6 comments · Fixed by #518
Labels
context-v3 Related to tailwind-merge v3 feature Is new feature

Comments

@dcastil
Copy link
Owner

dcastil commented Jan 16, 2025

Tailwind CSS v4 will be released next week: https://x.com/adamwathan/status/1879856208552845570.

I expect to add support for it a few days after the Tailwind CSS v4 release. Most probably it will be a new major tailwind-merge version with the only breaking change being that it supports Tailwind CSS v4 instead of v3.

Feel free to subscribe to this issue to get notified when support for Tailwind CSS v4 lands.

Some additional info in #468.

Changes to check

✅ Tailwind CSS v4 annnouncement

Tailwind CSS v4 annnouncement

✅ Upgrade guide

Upgrade guide

✅ Utility schemas

✅ Syntax changes

#513 (comment)

  • Important modifier is at the end now (but beginning supported too for BC)
  • New shorthand syntax for variables as arbitrary values
  • Respect variant order from Tailwind CSS when not reorderable Tailwind CSS v4 support #513 (comment)
  • Prefixes look like variants, and always come first
  • Arbitrary variants support HTML elements now and don't always require an &

Issues discovered

@dcastil dcastil added the feature Is new feature label Jan 16, 2025
@dcastil dcastil pinned this issue Jan 16, 2025
@github-actions github-actions bot added the context-v2 Related to tailwind-merge v2 label Jan 16, 2025
@dcastil dcastil added context-v3 Related to tailwind-merge v3 and removed context-v2 Related to tailwind-merge v2 labels Jan 24, 2025
@dcastil
Copy link
Owner Author

dcastil commented Jan 24, 2025

@adamwathan Are there any syntax-related changes in Tailwind CSS v4 that I should be aware of that weren't mentioned in the announcement post or upgrade guide?

@Bricklou
Copy link

Bricklou commented Jan 24, 2025

@adamwathan
Copy link

@adamwathan Are there any syntax-related changes in Tailwind CSS v4 that I should be aware of that weren't mentioned in the announcement post or upgrade guide?

I think the only syntax-ish changes are these:

  • Important modifier is at the end now (but beginning supported too for BC)
    • !underlineunderline!
  • New shorthand syntax for variables as arbitrary values
    • w-[--my-var]w-(--my-var)
  • Variants are applied in reverse order from v3
    • before:*:underline*:before:underline
  • Prefixes look like variants, and always come first
    • dark:lg:tw-underlinetw:dark:lg:tw-underline
  • Arbitrary variants support HTML elements now and don't always require an &
    • [p]:underline adds an underline if the element is a p tag

I think that's everything 👍

@dcastil
Copy link
Owner Author

dcastil commented Jan 25, 2025

@adamwathan awesome, thanks for the list!

I wonder: Do you have some code in the Tailwind CSS codebase that checks whether variants are reorderable? E.g. in hover:focus:x the order doesn't matter but in focus:before:hover:x it does.

tailwind-merge sorts variants internally (between arbitrary variants) to allow better deduplication, but maybe it isn't feasible anymore to do that.

@adamwathan
Copy link

@dcastil I think there is some stuff for that sort of thing here:

https://github.com/tailwindlabs/tailwindcss/blob/next/packages/%40tailwindcss-upgrade/src/template/codemods/variant-order.ts

Here's the tests which explain what it changes and doesn't change:

https://github.com/tailwindlabs/tailwindcss/blob/next/packages/%40tailwindcss-upgrade/src/template/codemods/variant-order.test.ts

Copy link

This was addressed in release v3.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
context-v3 Related to tailwind-merge v3 feature Is new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants