How are colors specified in HTML/CSS?
Colors are built from RGB — red, green and blue light mixed together — most often written as a hexadecimal #RRGGBB code.
A screen makes every color by combining three colored lights. In CSS you specify how much of each with a hex code: #RRGGBB, where each two-digit pair runs from 00 (none of that light) to FF (full intensity, 255 in decimal).
| Color | Hex Code | Why |
|---|---|---|
| Red | #FF0000 |
full red, no green, no blue |
| Lime | #00FF00 |
green channel at full |
| Blue | #0000FF |
only blue at full |
| White | #FFFFFF |
all three at full = all light = white |
| Black | #000000 |
no light at all = black |
Notice the logic: full of everything is white, none of anything is black — the opposite of mixing paint.
A common trap: full green light is #00FF00, but its standard CSS color name is lime, not green — the keyword green is actually the darker #008000. So #00FF00 looks bright green, yet color: green gives you a muted one. A set of common colors have such plain-English names you can use directly:
color: red;
color: navy;
color: teal;
Two handy shortcuts: a three-digit form #RGB expands by doubling each digit, so #F00 means #FF0000 (red); and hex codes are case-insensitive, so #ff0000 and #FF0000 are identical.
Go deeper:
RGB color model — Wikipedia — additive color mixing explained with Venn diagrams, the RGB cube, and how screens build color from sub-pixels.