Managing color variables in front-end project

In every frontend code we use a lot of colours in scss.

First bit of optimisation is to put all the colour variables in a separate file, so that we can get all the colours used in our project at one place

Now second bit is about giving proper names to these colour variable so that we get an idea just by looking at the name.

So I consider two types of colours

  1. gray colors (gray, black and white)
  2. non-gray colors (rest other colors)

Below is an approach that I am following and finding helpful for gray colours

  1. use rgb for black, gray and white colours and their name should follow an approach like if the colour is rgb(24,24,24) then it’s name would be $black-24
  2. I put threshold on black till $black-80, further numbers would be gray and threshold on gray till $gray-223, further colour variables would be $white-224
  3. if any color has to be used with opacity, -a<% of opacity> immediately after name like $black-a20, here 20 signifies, 20% opacity

Approach for non-gray colors

I use hsl for colours other than gray, checkout this link for the reason

Now coming to naming these variable, following are the rules I useto put the name of the color.

  1. for a color hsl(346, 77%, 44%) the name would be $red-346 because
  • it looks red
  • it’s degree is 346

2. for a color hsl(346, 76%, 10%) the name would be $brown-346 because

  • it looks brown
  • it’s degree is 346

3. for a color hsl(346, 76%, 60%) the name would be $red-346-2 because

  • it looks red
  • it’s degree is 346
  • -2 because I already have one color with $red-346

4. for a color hsla(346, 76%, 60%,.2) the name would be $lightBrown-a20-346 because

  • it looks lightBrownish
  • it’s opacity is 20%
  • it’s degree is 346

What do you think about these strategy, please let me know if you have any comments or suggestions!

I love learning