hexadecimal – What happens to 3-digit hex colors?


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 the color black. And fff or ffffff which is white. There are also other colors which is F00 which is red.

But there remains a curiosity:

  • How would I translate this 3-digit hex color to 6-digit hex color?

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


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

So the #F3A code is transformed to #FF33AA .

Translated from https://stackoverflow.com/a/10230746/5230740 .

Scroll to Top