Finding something worth knowing…

Health

Web colours rest on 24 bits, enough for 16,777,216 distinct shades

Every hex colour code on the web packs three bytes, one each for red, green and blue, with intensities running from 0 to 255. That adds up to 24 bits and 16,777,216 possible colours. A hardwood brown with channel values of 123, 58 and 30 becomes the code 7B3A1E.

A web colour can be given as an RGB triplet, as a hexadecimal triplet, or in some cases by a plain English name. Each channel gets two hex digits, from 00 to FF, so a full code runs to six digits; an optional extra pair adds an alpha channel for transparency. Values below 16 need a leading zero to keep the length fixed, which is why the decimal triple 4, 8 and 16 is written 040810.

Converting by hand is simple arithmetic. Divide a channel value by sixteen: the whole-number result is the first digit and the remainder the second, with the letters A to F standing for 10 to 15. So 58 holds three sixteens with ten left over, giving 3A, and 201 becomes C9. A three-digit shorthand also exists, expanded by doubling each digit so that 09C turns into 0099CC, but it limits the palette to 4,096 colours, the equivalent of 12-bit colour, and can trip up software expecting the long form.

Behind the codes lies sRGB, a precise colorimetric definition tied to a set of phosphors, a transfer curve, a white point and viewing conditions chosen to resemble ordinary monitors, so colours look roughly right even without colour management. CSS can reach beyond sRGB by pushing channels below zero or above 100 percent, but only through its RGB function; hexadecimal notation has no way to express such values.

Named colours have a messy pedigree. The earliest versions of Mosaic and Netscape Navigator began life as X Window System programs, so they borrowed its X11 colour names. The HTML 4.01 specification, ratified in 1999, fixed 16 basic colours, which HTML 3.0 had described as the standard Windows VGA palette. Extended names came from merging several specifications, and by 2005 every mainstream graphical browser supported the full list.

Source: Web colors

Related

More in Health · All topics