What happens to the 3-digit hexadecimal colors?

12

I've always been curious to know what happens in a 3-digit hexadecimal expression of a color in CSS.

For example, you have 000 and 000000 , which is black. E fff or ffffff that is white. There are also other colors that are F00 which is red.

But there's a curiosity left:

  • How would I translate this 3-digit hexadecimal color into the 6-digit color?

  • Do you have any formula for turning hexadecimal from 3 to 6 color?

asked by anonymous 13.02.2017 / 13:29

3 answers

3

According to the W3C documentation on color units , the numeric values RGB are represented by hexadecimal notation, preceded by the character # .

They can contain 3 or 6 digits, being represented as follows:

EM { color: #f00 }              /* #rgb */
EM { color: #ff0000 }           /* #rrggbb */

What happens when you use only three digits is the replication of them in the rrggbb formula, so the #fb0 value has its characters replicated and expanded to #ffbb00 .

OBS : There are those who think that the three-digit value is filled with zeros to complete the value hexadecimal of six digits, and this is a big misconception!

@edit

  

How would I translate this 3-digit hexadecimal color into 6-digit color?

As explained above, simply replicate the characters, for example: fb0 becomes: ff , bb and 00 respectively, forming code: ffbb00 .

  

Do you have any formula for turning hexadecimal color from 3 to 6?

There is no specific formula for this "schema", the browser itself takes care of replication, but if it is for a specific use case, you can implement replication the way you want.

    
13.02.2017 / 13:49
7

3-digit hexadecimal colors are expanded by doubling each character (see w3 spec ).

So the code #F3A is transformed to #FF33AA .

Translated from link .

    
13.02.2017 / 13:34
2

It's simple, so read on.

Para #000 - RGB

Para #000000 - RRGGBB
    
13.02.2017 / 13:33