Skip to content

Colors opacity support in custom utility class #17238

Answered by wongjn
itsJohnnyGrid asked this question in Help
Discussion options

You must be logged in to vote

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);
}

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@itsJohnnyGrid
Comment options

@itsJohnnyGrid
Comment options

@wongjn
Comment options

wongjn Mar 17, 2025
Collaborator

@itsJohnnyGrid
Comment options

@wongjn
Comment options

wongjn Mar 17, 2025
Collaborator

Answer selected by itsJohnnyGrid
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