Skip to content

How to define custom color names with alpha/opacity support using default colors & having the same name in dark & light mode #13483

Answered by alex-krasikau
kpvhn asked this question in Help
Discussion options

You must be logged in to vote

Hey @kpvhn!

To achieve your goal, modify the tailwind.config color specification to utilize relative color syntax. Here's the updated code snippet:

colors: {
  primary: 'rgb(from var(--color-primary) r g b / <alpha-value>)',
}

Check out full example: https://play.tailwindcss.com/juMPtEAft4?file=config

Relative syntax is not universally supported in all modern browsers, but it is available in postcss-preset-env. This allows PostCSS to convert all colors to the compatible variant during the build process.

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@alex-krasikau
Comment options

@amishaaggarwal
Comment options

@kpvhn
Comment options

@amishaaggarwal
Comment options

@slashmili
Comment options

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