Colors in CSS3

Colors in CSS3

Colores en CSS3

The aim of this post is to see some characteristics of the recommendation of the color module in CSS3, specified in

The main change in the color use in CSS3 is the possibility of using models in rgb, rgba, hsl and hsla color. One of the principal vantages of this color models is that they ease the management of the different properties of the colors, besides applying an opacity level to color. The hsl model, which is the one I want to stand out, is a more intuitive model as it indicates the hue, saturation and brightness values and it allow us to create color palettes in a more simple way by doing variations in some of the values of the hsl model. The saturation value is represented by an angle of the color wheel, which is measured in degrees, although only the number is specified from 0 to 360, where the red=0=360. The saturation and brightness are specified in percentages.

Now I am going to make an example in order to show how easy can be to create a color selector on the basis of the hsl model. To do this, I use the ‘input’ tag of range type, to ease the selection of the different values. This type will only work in some of the latest versions of the different browsers, given that it is a novelty in html5 forms If not specified, the ‘min’ and ‘max’ attributes of the range type will be 0 and 100, respectively, and we can assign to it a step scale factor, ‘step’, which is 1 by default. Next we create a JavaScript function which collects and update each of  ‘input’ values.

Besides the hsl model, we can use the hsla model, where ‘a’ specifies the color alpha value. This alpha value will be a number between 0.0 and 1.0 and it will be used as follows.

I will add to the previous example the use of the alpha value. To simulate the transparency of the way other image editing programs do it, as Photoshop or Fireworks, instead of using an image as background, I have used a pattern entirely done with CSS3. Many of us know this technique thanks to the Lea Verou patterns gallery.

Finally, using JavaScript we convert the different values into rgb and hexadecimal models.

©2024 PoseLab SL. All rights reserved.