v3→v4 upgrade: gradient buttons broken when using @import 'tailwindcss' (unlayered preflight overrides bg-linear-to-* utilities) #19979
stephanhink
started this conversation in
General
Replies: 1 comment
-
|
The However, when splitting, ensure you don't miss out any layers: -@layer theme, base, utilities;
+@layer theme, base, components, utilities;
@import 'tailwindcss/theme' layer(theme);
@import 'tailwindcss/preflight' layer(base);
-@import 'tailwindcss/utilities';
+@import 'tailwindcss/utilities' layer(utilities); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
After upgrading from Tailwind CSS v3 to v4 using
npx @tailwindcss/upgrade@latest, gradient buttons stopped working. The buttons rendered with a plain background instead of the gradient.Root Cause
The codemod replaces the old
@tailwind base/components/utilitiesdirectives with a single@import 'tailwindcss'. This single import causes the preflight rule:to land as unlayered CSS — meaning it sits outside any
@layerand therefore has higher precedence than Tailwind's layeredbg-linear-to-*utilities. The gradient gets silently overridden.Steps to Reproduce
<button>elements (e.g.bg-linear-to-r from-green-500 to-green-700— formerlybg-gradient-to-r).npx @tailwindcss/upgrade@latest.Fix
Replace the single
@import 'tailwindcss'with split imports that give you explicit layer control, and wrap all your own global styles in@layer base:This ensures
button { background-image: none }from preflight stays inside@layer base, and yourbg-linear-to-*utilities in@layer utilitiescorrectly take precedence.Related side effect:
space-x-*utilities stop workingIf you have a global reset like
* { margin: 0; padding: 0 }in your CSS outside any layer, it will silently breakspace-x-*and similar utilities. Tailwind v4 uses:where()selectors (specificity 0) for those utilities, so any unlayered*rule wins. The@layer basewrapper fixes this too.Environment
@tailwindcss/postcss: 4.2.4Suggestion
It would be great if the upgrade codemod could emit the split import form by default, or at least add a comment warning about the unlayered preflight behavior when gradient utilities or
space-x-*are detected in the project.Beta Was this translation helpful? Give feedback.
All reactions