-
Notifications
You must be signed in to change notification settings - Fork 230
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
CSS specificity issues w/ tailwind #109
Comments
I am having the same problem, but moving the import to the the css file made no difference to me. |
Those styles are a part of Import Radix Themes after @tailwind base;
@import "@radix-ui/themes";
@tailwind components;
@tailwind utilities; |
I'm aware of the problem so I opened this issue as a note for others. The behaviour is tricky because styles work as expected when developing locally. But when you push to prod, styles don't work. It is not clear in the docs and I suspect that a lot of people will run into this same issue.
This code snippet does not suggest anything about importing in the CSS file. Happy to create a PR for the docs site |
Changing the order of imports on the css file did not work for me, It worked only if i changed the order of imports in the layout.tsx (moving '@radix-ui/themes/styles.css' after all other css imports), but even that was not consistent and broke on prod. |
Good call, we'll work out a guide on using Radix Themes with Tailwind. We recently discovered that Next.js doesn’t always bundle css in the order you import it, so this might be a related factor too.
@3den not sure how this could be the case, could you double check with the example I mentioned above? If that still doesn't work, we'd need a repro sandbox to look into. |
I have moved the radix import after everything. import '@/styles/app.css';
import '@/styles/overrides.css';
import "@radix-ui/themes/styles.css"; That worked on localhost, but not on prod. It could be that next.js is not obeying the imports order. But even when it does this raises an other issue, having radix imports after tailwind will give it a higher specificity, forcing me to use |
@vladmoroz after updating to next |
@3den you need to import Radix Themes styles inside a CSS file right after |
@vladmoroz yes, I did that first, but It did not work. |
I even tried moving each part to its own css file like this /* Resets & Variables */
@import './base.css';
/* Dependencies */
@import 'react-quill/dist/quill.snow.css';
@import '@radix-ui/themes/styles.css';
/* Components */
@import './components.css';
@import './overrides.css'; What seems to happen is that next is splitting the css, into multiple files and for some reason the radix one is being loaded before tailwind, no matter what I do. On the code I shared before the imports where moved to before any other rules I'm trying to figure out how to disable next.js code splitting, which will likely solve this problem, but that feels hacky... IMO forcing the specificity to be lower than 011 is overkill, it was already very easy to override radix classes with important configs. |
We're having the same problem over here! |
@vladmoroz actually seems like @radix-ui css is aways slit to its own file: ![]() |
@vladmoroz works perfectly!!! 🥳 🎉 🍾 Thanks so much for the help 🍻 |
I find that the order of these files in either order will cause problems. Using the AlertDialog as an example:
if we do this:
Radix will override Tailwind and the OK button above will lose the Indigo color and show the theme color. This prevents me from overriding innate styles. If we do this:
Tailwind will override Radix and the OK button above will be Indigo as intended, but now the Cancel button will lose the theme color and be overridden by Tailwind's base css. My workaround is, in the layout.tsx file I'm importing the Radix css second (to override Tailwind's base css) and then I'm using Tailwind's selector strategy which prefixes all Tailwind utility classes with "#tw" so that they override Radix's classes. (Only utility classes will get prefixed, the base classes won't.) I also need to set the id of the body tag to "tw". |
This also fixed the issue for me - thanks so much. |
Solution credits to radix-ui/themes#109. Added postcss-import package, changed tailwind base to an import, then imported radix ui theme right after that. Suspected cause of bug was due to Nextjs not following the right order of css imports, causing tailwind css to override the radix ui one on the food tables page or something.
@vladmoroz just thought you might want to know about Next 14.2
|
@kylemh oh nice, thanks for surfacing it! |
In Next 14.2.14, this:
gives:
It doesn't happen if the imports are the other way around. |
In case anyone recently upgraded to Tailwind 4.0, here's what worked for me based on this thread and the docs:
I'm now able to add Tailwind styles to further customize/modify Radix Themes components. |
I recently updated to v2 of Radix Themes and noticed that some of my styles were now being overridden by Tailwind.
Notes: This is only in prod deployments via Vercel, styles are applied correctly when locally developing
My setup was as follows:
When doing this, the tailwind base styles were taking priority over my radix themes styling. Both specificity (0,1,0).

After playing around with some things, I have tried the following and now the styles are being applied correctly again.
To be honest I am not sure if this is the best option, but it has worked for me and may help others. It would be good to get some advice on this and best practices!
The text was updated successfully, but these errors were encountered: