What happens to three-digit hexadecimal colors?

Asked

Viewed 614 times

13

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

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

But a curiosity remains:

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

  • Has some formula to turn color hexadecimal from 3 to 6?

  • I think this can help you : https://www.w3.org/TR/2001/WD-css3-color-20010305#colorunits

3 answers

7

  • As well "...each character is expanded from the white"?

  • 1

    Corrected spelling error: folding each character

  • 1

    @Murillogoulart kkkkkkk

  • kkkkkkk now I understand

  • 1

    @Marcelodeandrade Certo!! A third edition made the mistake even worse. But beauty, what counts is the intention! hauhau

4


According to the documentation of W3C about color units, the numerical values RGB are represented by hexadecimal notation, preceded by the character #.

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

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

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

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

@Edit

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

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

Has some formula to turn color hexadecimal from 3 to 6?

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

  • 1

    I also thought I was filled with zeroes

  • Exactly, @Wallacemaxters. It’s a common misconception, and it goes unnoticed most of the time.

2

It’s simple, read it like this.

Para #000 - RGB

Para #000000 - RRGGBB

Browser other questions tagged

You are not signed in. Login or sign up in order to post.