13

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?

12
  • 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 9 at 15:52
  • 10
    @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…) Mar 9 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 9 at 16:04
  • 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 9 at 16:46
  • 8
    @texdr.aft yup, it’s a shame documentation authors never seem to predict and address Retro.SE questions ;-). Mar 9 at 17:59
14

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.

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). Mar 16 at 10:12
  • 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...). Mar 17 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 at 20:23
  • 1
    @TobySpeight Something like (x<<3)|(x>>2) ?
    – Leo B.
    Mar 18 at 6:13
  • 2
    Mosaic - 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. May 5 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.