Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do 3 digit hex css colors convert to 6 the way they do?

I'm aware that the method to convert a 3 digit hex css color to 6 digit code is by duplicating each hex digit once, as below.

#ABC === #AABBCC

Why does it work this way? Why isn't #ABC equivalent to #A0B0C0?

like image 550
danmcardle Avatar asked Dec 01 '22 22:12

danmcardle


1 Answers

From the W3C spec:

The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros. For example, #fb0 expands to #ffbb00. This ensures that white (#ffffff) can be specified with the short notation (#fff) and removes any dependencies on the color depth of the display.

You can read more about it here: http://www.w3.org/TR/css3-color/

like image 58
Francisco Paulo Avatar answered Dec 18 '22 05:12

Francisco Paulo