Skip to content

How to Create a Custom CSS Color Utility with Opacity Support (Tailwind text-* Replica) #18124

Answered by wongjn
AsadGG asked this question in Help
Discussion options

You must be logged in to vote

As per the documentation, you'd use --modifier():

@utility ion-text-* {
  --foo: calc(--modifier(integer) * 1%);
  --color: --alpha(--value(--color- *) / var(--foo, 100%));
}

As for how Tailwind core achieves this with its text-* utility, start from here:

let value = resolveThemeColor(candidate, theme, ['--text-color', '--color'])

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@AsadGG
Comment options

@wongjn
Comment options

wongjn May 23, 2025
Collaborator

Answer selected by AsadGG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants