on-internet
← Community

How do I apply opacity to a CSS color variable?

Stack Overflow ·

I have defined a color variable in vars.css: :root { --color: #f0f0f0; } I want to use this color in main.css, but with some opacity applied: #element { background: (somehow use var(--color) at some opacity); } How would I go about doing this? I am not using any preprocessor, only CSS. I would prefer an all-CSS answer, but I will accept JavaScript/jQuery. I cannot use opacity because I am using a background image that should not be transparent.

Comments

Sign in or sign up to comment and upvote.

No comments yet.