CSS RGB and RGBA in CSS

I learned about RGB and RGBA while reading how to define colors in Cascading Style Sheets.

Admin

1 min read

RGB is one notation through which colors may be set using a style sheet for a webpage. The rgb() function takes three numerical values separated by a comma and each representing the colors Red, Blue and Green in the respective order.

The values can be between 0 and 255, inclusive.

rgb(46,139,87)

The above example represents a shade of Green.

Using the rgba() function, one may control the alpha channel to adjust the transparency. The function requires a fourth numerical value which can be a decimal value between 0 and 1; the latter being complete opaque and 0 meaning full transparency.

Applying a 50% transparency to the above example would give us:

rgba(46,139,87,0.5)

Notice, how the Green further changes its shade.


Read more about Colors & CSS at w3.org.
Image credit: Education photo created by user18526052