everything about web

A Comprehensive Guide to the World of Web Design & Development:

CSS, HTML, Performance, Web Design, and all Aspects of Front-End Development

Advertisements

A Complete Guide for CSS Color Model

A Complete Guide for CSS Color Model - This article is a complete guide regarding the CSS color model for rgb(), rgba(), hsl(), hsla and hwb().

RGB Color Model

#RRGGBB[AA] or #RGB[A]

#RRGGBB[AA] is formed by color components from RR (red), GG (green), BB (blue), and AA (alpha)

  • The value from RR (red), GG (green), BB (blue), and AA (alpha) are hexadecimal characters (value falls between 00–99, AA–FF). 
  • The value from AA (alpha) is optional. 

In this example, the color code #FF0000 will be displayed in red. This is because the red component is set to its highest value (FF) and the other color component are set in the lowest value, which is 00.

To add transparency, add the value AA (alpha) in the rear.

More examples:

background-color:#FF0000;
background-color:#F00;
background-color:#FF000033;
background-color:#F003;
background-color:#00FF00;
background-color:#0000FF;

The #RGB[A] is a shorter version of the #RRGGBB[AA]. For eg, #F003 is the same color as #FF000033.

rgb() or rgba()

rgba() is formed by the color components from r (red), g (green), b (blue), and a (alpha)

  • The value from r (red), g (green), b (blue) are formed by integer numbers (value falls between 0-255). 
  • a (alpha) is optional (value falls between 0.00 - 1.00). 

In this example, the CSS code rgba(255,0,0) will displayed in red color, this is because the red component is set to its highest value (255) and the other color component are set to 0.

To add transparency, add in the value a (alpha) in the rear. The alpha value falls between 0.00 (fully transparent) to 1.00 (fully opaque).

More examples:

rgb():

background-color:rgb(255,0,0);

rgba():

background-color: rgba(255,0,0,1);
background-color: rgba(255,0,0,0.2);
background-color: rgba(0,255,0,1);
background-color: rgba(0,0,255,1);

HSL Color Model

hsl() or hsla()

hsla() is formed by the color components from h (hue), s (saturation), l (lightness), and a (alpha)

Color wheel:
0deg (red)
120deg (green)
240deg (blue)
  • The value from h(hue) is referring to the degree on the color wheel
    • 0deg or 360deg is red, 120deg is green, 240deg is blue
    • value falls between 0-360
  • The value from s(saturation) is referring to the percentage of the saturation
    • 0% is completely unsaturated (gray) and 100% is the full color
    • value falls between 0-100%
  • The value from l(lightness) is referring to the percentage of the lightness
    • 0% is black, 100% is white
    • value falls between 0-100%
  • The value from a(alpha) is referring to the percentage of the transparency
    • a (alpha) is optional
    • 0% is fully transparent, 100% is fully opaque
    • value falls 0.00 - 1.00

In this example, hsla(360, 100%, 50%, 1) will displayed in red

More examples:

hsl():

background-color:hsl(360, 100%, 50%);

hsla():

background-color:hsla(360, 100%, 50%, 1);
background-color:hsla(360, 100%, 50%, 0.2);
background-color:hsla(120, 100%, 50%, 1);
background-color:hsla(240, 100%, 50%, 1);

HWB Color Model

hwb()

hwb() is formed by the color components from h (hue), s (whiteness), l (blackness), and a (alpha)*Optional

  • Similar with hsl() color model, The value from h(hue) is referring to the degree on the color wheel
    • 0deg or 360deg is red, 120deg is green, 240deg is blue
    • value falls between 0-360
  • The value from w(whiteness) is referring to the percentage of the whiteness while b(blackness) is referring to the percentage of the blackness. Both colors will be mixed to produce the final result:
    • for eg: 0% of whiteness + 100% of blackness to produce a black color.
    • value falls between 0-100%
  • The value from a(alpha) is referring to the percentage of the transparency
    • a (alpha) is optional
    • 0% is fully transparent, 100% is fully opaque
    • value falls between 0-100%

For example,

  • hwb(360 0% 0%/ 20%) = red, opacity 20%
  • hwb(0 0% 100%) = black
  • hwb(0 100% 0%) = white
background-color:hwb(360 0% 0% / 100%);
background-color:hwb(360 0% 0% / 20%);
background-color:hwb(120 0% 0%/ 1);
background-color:hwb(240 0% 0%/ 100%);
background-color:hwb(0 100% 0%);
background-color:hwb(0 0% 100%);
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

If you found this article helpful and would like to show your support, you can buy me a coffee using the link below. Thanks a bunch!

Choose an amount

$5.00
$10.00
$15.00

Or enter a custom amount

$

Thank you for your contribution!

Donate

Topics:

CSS (27) css pseudo (3) debug (2) design (4) fonts (2) html (6) image (8) layout (5) optimization (10) performance (9) responsive (8) Software-development (1)


Advertisements

Recent Post:

Advertisements

Related Posts

Advertisements
Advertisements
%d bloggers like this: