0

Is it possible to get R, G and B from HEX color in CSS?

For example if I have #00fbff I want to know RGB from this color (0, 251, 255), I'd like to know if it's possible to get the separate values. Because I'm trying to use HSL and, if I understand it well, I need these RGB values.

Taryn East
  • 27,486
  • 9
  • 86
  • 108
  • 1
    If you're trying to convert from HSL to RGB [see here](https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion). – Daniel Beck Jun 21 '21 at 18:56
  • As CSS is a declarative language, there's no way to "convert" between color formats *in CSS*. However, you can convert it by hand with [one of the many online converters](https://www.google.com/search?q=color+converter+online) – FZs Jun 21 '21 at 19:10

1 Answers1

0

If I understood you correctly you want to retrieve the separate red,green, and blue values from a css color so basically:

--my-color: #abcdef;
--my-color-red: /* Dynamic expression that evaluates to */ #ab0000 /* Based on var(--my-color) */;
--my-color-green: /* same as before but green */ #00cd00;
--my-color-blue: /* ... */ #0000ef

If this is what you want, then there currently isn't a way although there are 2 proposals:

  1. relative colors
  2. and color-adust which will solve your problem however they aren't available for use yet. In the mean time you could easily use a tiny bit of javascript to accomplish this
Zachiah
  • 1,750
  • 7
  • 28