Understanding Color Models
Digital colors are represented using mathematical models that define how colors are stored and displayed. The three most common models in web development are HEX, RGB, and HSL. Each model describes the same set of colors but uses different parameters, making some models more intuitive for certain tasks. HEX is the most compact notation, RGB maps directly to how screens produce color, and HSL aligns with how humans naturally perceive and describe color relationships.
HEX (Hexadecimal) colors use a six-character code preceded by a hash symbol, such as #2563EB. Each pair of characters represents the Red, Green, and Blue channels respectively, with values ranging from 00 (0) to FF (255). HEX is the most widely used color format in CSS and HTML because of its compactness. The shorthand notation (e.g., #FFF for #FFFFFF) is available when both characters in each pair are identical.
RGB (Red, Green, Blue) defines colors by specifying the intensity of each primary color channel as a value between 0 and 255. The notation rgb(37, 99, 235) tells the browser to mix those specific intensities of red, green, and blue light. This additive color model directly corresponds to how LCD and LED displays work: each pixel contains red, green, and blue sub-pixels whose brightness levels combine to produce the perceived color.
HSL (Hue, Saturation, Lightness) describes colors in terms that humans find intuitive. Hue is the color angle on the color wheel (0-360 degrees), where 0 is red, 120 is green, and 240 is blue. Saturation controls how vivid or muted the color appears (0% is grayscale, 100% is fully saturated). Lightness controls how bright or dark the color is (0% is black, 100% is white, 50% is the pure color). HSL makes it easy to create color variations: you can lighten a color by increasing lightness or create a muted version by reducing saturation.