Skip to content

Remove CSS variables for color opacity #2620

Closed Answered by saadeghi
icaliman asked this question in Q&A
Discussion options

You must be logged in to vote

Those CSS variables are not from daisyUI. It's from Tailwind CSS.

The reason Tailwind CSS using CSS variables for that:
There are utility classes like bg-opacity-50.

For example people can use bg-red-500 bg-opacity-20

It creates these style:

.bg-red-500 {
  --tw-bg-opacity: 1;
  background-color: rgb(239 68 68 / var(--tw-bg-opacity));
}
.bg-opacity-20 {
  --tw-bg-opacity: 0.2;
}

There's no other way to control the color value and opacity using 2 separate class names.

There are PostCSS plugins that can remove unnecessary CSS variables but I don't guarantee that they won't break some styles.

My advice: don't worry about these small optimizations. Best case you may save only a few bytes in e…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by saadeghi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants