CSS colour formats explained
Hex is the most common CSS colour format. A six-digit hex code like #ff6b35 defines red, green, and blue channels as two hex digits each (00–ff, or 0–255 in decimal). Three-digit shorthand (#f63) doubles each digit: #ff6633. Eight-digit hex adds an alpha channel: #ff6b3580 is 50% transparent.
RGB functional notation — rgb(255, 107, 53) — specifies the same channels in decimal. Modern CSS also supports rgb(255 107 53 / 0.5) with a slash-separated alpha value. RGB maps directly to how screens produce colour by mixing red, green, and blue light.
HSL — hsl(20, 100%, 60%) — represents colour as Hue (0–360° on the colour wheel), Saturation (0–100%, grey to vivid), and Lightness (0–100%, black to white). HSL is more intuitive for creating colour systems: to make a colour lighter, increase lightness; to desaturate, reduce saturation. Designers often prefer HSL for building palettes.
CSS defines 148 named colours from aliceblue to yellowgreen. These are convenient for quick prototyping but offer limited precision. Most production code uses hex or HSL for exact colour control.
Colour accessibility basics
The Web Content Accessibility Guidelines (WCAG) define minimum contrast ratios between text and its background to ensure readability. The contrast ratio ranges from 1:1 (no contrast) to 21:1 (black on white). WCAG Level AA requires at least 4.5:1 for normal text and 3:1 for large text (18px+ or 14px+ bold). Level AAA requires 7:1 for normal text and 4.5:1 for large text.
This tool calculates the contrast ratio of your colour against both white and black backgrounds using the WCAG relative luminance formula. When designing interfaces, always verify that your text colours meet at least AA standards. Low contrast is one of the most common accessibility issues on the web — and one of the easiest to fix.