Colors opacity support in custom utility class #17238
Answered
by
wongjn
itsJohnnyGrid
asked this question in
Help
-
Hi, I defined utility class in my @utility text-default {
color: var(--color-gray-900);
} However, when I try to apply opacity (e.g., I’ve carefully read the docs and tried various solutions found online, but none seem to resolve the issue. Could someone advise on how to make this work with Tailwind 4? 🙏 |
Beta Was this translation helpful? Give feedback.
Answered by
wongjn
Mar 17, 2025
Replies: 1 comment 5 replies
-
You could consider setting a new theme value for this instead of making a custom utility: @theme {
--color-default: var(--color-gray-900);
/* Or for text only: */
--text-color-default: var(--color-gray-900);
} Or if you still really want to create a utility, you still have to make a theme variable since only dynamic utilities can have modifiers: @theme {
--foo-default: var(--color-gray-900);
}
@utility text-* {
--alpha: calc(--modifier(integer) * 1%);
color: color-mix(in oklch, --value(--foo-*) var(--alpha, 100%), transparent);
} |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
itsJohnnyGrid
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You could consider setting a new theme value for this instead of making a custom utility:
Or if you still really want to create a utility, you still have to make a theme variable since only dynamic utilities can have modifiers: