The difference between hex color, RGB and RGBA, and when should each be used?

When studying textbooks on a variety of topics, I often saw that RGB and RGBA are used instead of hexadecimal codes for colors in HTML / CSS.

Can someone explain to me what is the difference between RGB, RGBA, hex and when should each be used / advantage of using one over the other?

+4
source share
3 answers

There is no difference between RGB and hexadecimal color.

hex to decimal:

Ff = 255

therefore #FFFFFF = rgb (255,255,255)

When you break the hex color:

#FF  FF    FF
red green blue

rgb a () -, .

RGB HEX, .

:

div {
 width:100px;
 height:100px;
 border:solid 1px black;
}

.rgb{
  background-color:rgb(124,220,50); /* to hexa = 7C DC 32 */
}

.hexa{
  background-color:#7CDC32;
}

.rgba{
  background-color:rgba(124,220,50,0.2); /*opacity = 0.2/1 */
}
<div class="rgb">rgb</div>
<div class="hexa">hexa</div>
<div class="rgba">rgba</div>
Hide result
+7

RGB RGBA : " ". "A" → Alpha

RGB ( ) RGBA ( )

-, , . ( 0.0 - 1.0)

RGB/RGBA HEX , HEX 6 . () RGB 3 3 , 0-255.

, , .

+4

RGB values ​​(red, green, blue) are more archaic, but are commonly used in a variety of industries, including printing and publishing. It used to be more widely used on sites than today.

RGBA (red, green, blue, alpha) is used for transparent color. The value for A (alpha) is from 0, completely transparent, to 1 completely opaque.

hex is a more recent fast value used exclusively for websites and applications.

+3
source

Source: https://habr.com/ru/post/1662518/


All Articles