Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Swapping the color notation in CSS #19

kizu opened this Issue Oct 27, 2012 · 4 comments


None yet
3 participants

kizu commented Oct 27, 2012

Colors in CSS can be described in different ways: Hexadecimal, rgb, rgba, hsl and hsla.

Right now the dec_max and dec_all actions are the same for the colors, so we could change one of them to the new action: rotate the notation for the color.

That way, the color described as #FFF would become rgba(255,255,255,1) and then hsla(0,0%,100%,1) (plain rgb and hsl are rarely used, so we could just forgot about them)

If the color have the alpha less than 1, we could rotate only between rgba and hsla, so we wouldn't lose the alpha occasionally.

There could still be some issues, like not every color in RGB can be described in HSL, but we could either just forgot about that, either add a comment with the initial color after the transform, that could be used to restore the color to it's previous state if it was changed. Actually, doing so we could keep the alpha for the switching to hexadecimal color.

This way the chain would look like:

  1. color: rgba(255,255,255,0.5);
  2. color: hsla(0,0%,100%,0.5);
  3. color: #FFF; /* alpha: 0.5 */
  4. color: rgba(255,255,255,0.5); again.

This would allow us to easy change the color defined in any notation using the appropriate way we want.


rmaksim commented Oct 28, 2012

Try to test.
Now only two transformations are available.


color: rgba(0,17,34,0.4);


color: #001122; /* alpha: 0.4 */


color: rgba(0,17,34,0.4);

kizu commented Oct 28, 2012

Aha, it works! Cool.

Some thoughts:

  • When the alpha: 1 the comment is unnecessary.
  • It would be cool to somehow preserve the case of the initial hexadecimal colors, however the only way to do it is to add the settings for this (two of them — the case of the letters and if they need to be shorthanded).
  • If would be nice to somehow validate the input of the rgba value: incorrect values like rgba(256,255,255,1) or rgba(-2,255,255,1) are converted too. That's not a big issue, but, well. Maybe it could be completely another issue — we could cycle the 255 to 0, so it couldn't go out of available range.

rmaksim commented Oct 28, 2012

Yeah, have been thought - but a little later.

That's cool.

Here are some of my thoughts:

  • A color in RGB or HEX should not be converted to RGBA, and then also the comment is irrelevant (point 1 by kizu).
  • There should be a setting to use shorthand HEX values when possible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment