14

The hexadecimal notation #RRGGBB for RGB colour triples has been popularised by HTML and is commonly associated with it, even though nowadays it is not usually used in HTML directly, but rather through CSS.

I noticed that the same notation is used in the X pixmap format (XPM), which to my knowledge was created in 1989, thus predating HTML (1993).

Where does this notation come from? How did it end up in HTML?

user3840170
  • 23,072
  • 4
  • 91
  • 150
  • 5
    This probably has no "answer" in the accepted definition on stack exchange and this site as the notation is the natural one in a world where programmer's commonly deal with machine representations of numbers. Hexadecimal notation was common at that time (as it still is). If there had been color displays a decade earlier RGB notation might have been written in octal - that would have been natural for 666 color on 18-bit or 36 bit machines ... but they still would have switched to hex notation for color when the whole industry went that way ... – davidbak Mar 09 '21 at 15:52
  • 11
    @davidbak: Oh come on. The question about $ and about 0x managed to be answered. (I can’t speak as for the correctness of the answer, but…) – user3840170 Mar 09 '21 at 15:59
  • 2
    After glancing at early HTML specifications, I believe that coloring was introduced (i.e., specified; it might have been implemented earlier) only by HTML 3.2, in 1997. Previous versions don't say anything about color, and # is used solely for IDs and entity references. The HTML 3.2 specification mentions that the the 16 "standard" colors were derived from the Windows VGA palette; that might be a lead. – texdr.aft Mar 09 '21 at 16:04
  • 3
    If I'm wrong, I'm wrong. That's fine. And that's why I commented, not answered. @texdr.aft - Windows did use that notation as early as 2.0, probably in 1.0 though I don't know. – davidbak Mar 09 '21 at 16:17
  • 4
    @davidbak Good to know. It seems likely that it comes from a convention for hexadecimal numbers in general. Wikipedia, without citing any sources, agrees and says that the exact origin was X11 (or an early version thereof) color notation, which was in turn inspired by some assemblers. So far I haven't been able to find any old X windows documentation to verify the claim. – texdr.aft Mar 09 '21 at 16:46
  • This historical archive of early versions of X's rgb.txt does not have colors in hexadecimal; I'm not sure what to make of that. – texdr.aft Mar 09 '21 at 17:26
  • 2
    @texdr.aft however the X11R3 manuals describe RGB colour triplets in #-prefixed hex notation, with up to four hex digits per component. – Stephen Kitt Mar 09 '21 at 17:28
  • @StephenKitt As does the X11R1 documentation (apparently from 1987). But it doesn't seem to mention the origin of the notation. – texdr.aft Mar 09 '21 at 17:57
  • 8
    @texdr.aft yup, it’s a shame documentation authors never seem to predict and address Retro.SE questions ;-). – Stephen Kitt Mar 09 '21 at 17:59
  • @texdr.aft not in colors.txt but the X man page has it: https://cgit.freedesktop.org/~alanc/xc-historical/tree/xc/doc/man/general/X.man?id=8ff23fe979c40b2ed98373b43986484f6b045f0d has it and says it it's older. – Jasen Mar 13 '21 at 19:59
  • @Jasen - I don't see where that doc says it's older, could you point it out please? (It probably doesn't help that I'm reading the raw markup, not the formatted page). – dave Mar 13 '21 at 23:53
  • you're right, it doesn't say that it's older, ony the current documentation says that. (preferring rgb:XXXXXX or rgba:XXXXXXXX instead) – Jasen Mar 14 '21 at 00:59

1 Answers1

17

HTML colours came from X11, being slightly altered first.

https://en.wikipedia.org/wiki/X11_color_names

The #RGB and #RRGGBB syntax used by WWW was previously present in X11 too.

This 1988 commit tp the X(7) man page describes it (see the section "color names")

xsetroot ( historical version ) calls XParseColor(), and while the current man page for XParseColor() lists #RRGGBB as an allowed format, I was unable to find the corresponding man page on the Xorg site, though the content seems similar to the X(7) page above.

Interestingly, the current man page for XParseColor says that #RGB is scaled to #R0G0B0 rather than #RRGGBB, so #FFF is the same as #F0F0F0 under X11 rather than #FFFFFF (like it is for WWW). This is another departure from X11.

Toby Speight
  • 1,611
  • 14
  • 31
Jasen
  • 441
  • 2
  • 7
  • Would be good to also include how did it happen that X11 syntax ended up in HTML (as far as I can find, HTML colours were a Netscape invention, and Netscape was primarily an X client, so my guess is that this is where it specifically came from), and where X11 itself took it from (this one might be harder). – user3840170 Mar 16 '21 at 10:12
  • I can't say sure sure if it was netscape or mosaic. – Jasen Mar 16 '21 at 10:54
  • 1
    Interesting that it specifies zero-extension like that - I would consider that a specification error. (I once wrote some code that had to extend 5 bit-per-channel images up to 8 bit-per-channel and made absolutely sure that 1F multiplied up to become FF...). – Toby Speight Mar 17 '21 at 16:40
  • 2
    Yeah, that is an oddity. perhaps that why it is now deprecated in X11, rgb:fff , the new form, expands to rgb:ffffffffffff. I tested #FFF and it does indeed expand to #F0F0F0 – Jasen Mar 17 '21 at 20:23
  • 1
    @TobySpeight Something like (x<<3)|(x>>2) ? – Leo B. Mar 18 '21 at 06:13
  • @LeoB., yes, something like that (somewhat different because three channels were packed into two 8-bit bytes). – Toby Speight Mar 18 '21 at 07:34
  • 4
    Mosaic - https://en.wikipedia.org/wiki/Mosaic_(web_browser) - was originally written for X11 on Unix (PC's were not powerful enough yet). Mosaic was the base for Netscape which essentially defined the initial world wide web, so I agree that the X11 notation is a very good guess. – Thorbjørn Ravn Andersen May 05 '21 at 16:28