Color Models Explained
Every color you see on screen can be described by multiple mathematical models. Understanding the differences between them is the first step to choosing the right format for your project.
- HEX is the most common web color notation. A six-character string like
#3b82f6encodes red, green, and blue channels as two hexadecimal digits each. Three-character shorthand such as#fffexpands by doubling each digit to#ffffff. - RGB represents colors as an additive mix of red, green, and blue light, each ranging from 0 to 255. It maps directly to how monitors emit color, making it the native format for screens and image manipulation libraries.
- HSL (Hue, Saturation, Lightness) describes color the way humans think about it. Hue is an angle on the color wheel (0-360), saturation is the intensity (0-100%), and lightness controls how bright or dark the color appears (0-100%). This makes it intuitive to create tints, shades, and complementary palettes by adjusting a single value.
- HSV / HSB (Hue, Saturation, Value / Brightness) is closely related to HSL but defines brightness differently. In HSV, 100% value means the color is fully bright regardless of saturation, which is why most visual color pickers in design tools like Figma, Photoshop, and Sketch use HSV rather than HSL.
When to Use Which Format
Choosing the right color model depends on what you are trying to accomplish. Each format has practical strengths in certain workflows.
- HEX for CSS and branding. It is compact, universally supported, and easy to paste into stylesheets. Most brand guidelines ship their palette as HEX values.
- RGB for programmatic manipulation. When you need to blend colors, apply alpha compositing, or manipulate pixel data in a canvas or image library, RGB is the natural choice because the math operates directly on the channel values.
- HSL for design systems. Need a darker variant of your primary color? Lower the lightness. Want a muted background? Reduce saturation. HSL lets you create coherent palettes by tweaking one axis at a time. Modern CSS supports
hsl()natively, making it a great choice for design tokens and theming. - HSV for color pickers. If you are building a custom color picker UI or need to match values from Figma or Photoshop, HSV aligns with the way those tools present color selection. Converting to HSV ensures your picker output matches the visual representation.
Common Color Conversion Gotchas
Converting between color models is mostly straightforward, but there are a few pitfalls that regularly trip up developers.
- Rounding errors. HSL and HSV use percentages and degrees that don't always map to exact integer RGB values. Converting from HSL to RGB and back may shift a value by one unit. This tool rounds to the nearest integer for RGB channels and to one decimal place for HSL/HSV, which is sufficient for CSS but worth noting if you need lossless round-trip fidelity.
- Alpha channel handling. HEX can include an alpha channel as a fourth byte (e.g.
#3b82f680), and CSS supportsrgba()andhsla()functions. Not all conversion tools account for alpha, which can silently discard transparency. - Shorthand HEX expansion.
#fffis equivalent to#ffffff, not#0f0f0f. Each character is doubled, not zero-padded. Similarly, four-digit shorthand like#f008expands to#ff000088. - CSS color function syntax. Modern CSS uses space-separated values with an optional slash for alpha:
rgb(59 130 246 / 0.5)instead of the legacy comma-separatedrgba(59, 130, 246, 0.5). Both are valid, but mixing them up causes syntax errors.
Color Accessibility and Contrast
Color choice directly affects whether your content is readable. The Web Content Accessibility Guidelines (WCAG) define minimum contrast ratios between foreground text and its background to ensure legibility for users with low vision or color deficiencies.
- WCAG AA requires a contrast ratio of at least 4.5:1 for normal text and 3:1 for large text (18px+ bold or 24px+ regular). This is the baseline for most compliance requirements.
- WCAG AAA raises the bar to 7:1 for normal text and 4.5:1 for large text, providing enhanced readability.
- Lightness is the key lever. Contrast ratio is derived from relative luminance, which is most sensitive to the lightness component. When using HSL, checking the L value gives you a quick approximation: text with L below 40% on a white background typically meets AA, but always verify with a proper contrast checker.
- Don't rely on color alone. Roughly 8% of men have some form of color vision deficiency. Use shape, pattern, or text labels alongside color to convey meaning. If your UI uses red and green to indicate error and success states, add icons or labels as well.
Converting your brand colors to HSL makes it easier to generate accessible variants. Keep the hue fixed, then adjust saturation and lightness until the contrast ratio meets your target.
Related Tools
If you work with color values regularly, these tools may also be useful:
- Hex to Decimal Converter — convert any hexadecimal value (including individual color channel bytes) to its decimal equivalent and vice versa.
- CSS Minifier — after finalizing your color values, minify your stylesheets to reduce file size. The minifier can also convert long-form HEX values to shorthand where possible.
- HTML Beautifier — reformat inline styles and markup to make color declarations easier to scan and update.