FlowingDev

Color models, explained: how your computer speaks rainbow

Learn how computers represent color with models like HEX, RGB, HSL, and OKLCH, and why converting between them is crucial for web design and accessibility.

Try the tool: Color Picker & Converter

In one sentence

Color models are standardized systems for representing colors as numbers, allowing devices like screens and printers to create and share them consistently.

The problem it solves

Ever wonder why the same color can be written as #FF6347, rgb(255, 99, 71), and hsl(9, 100%, 64%)? It's because we have different "languages" for describing color, and each was born to solve a different problem.

In the beginning, there was the Cathode-Ray Tube (CRT) monitor. These bulky beasts worked by shooting electron guns at a phosphorescent screen. They had three guns: one for Red, one for Green, and one for Blue. By varying the intensity of each gun, they could mix light to create a whole spectrum of colors. This physical reality gave us the RGB model—it's a direct instruction set for the hardware. (255, 0, 0) meant "turn the red gun to max, and leave green and blue off." It was logical for the machine.

But it wasn't logical for humans. We don't think in terms of light-gun intensity. We think, "I want a brighter, more saturated orange." This disconnect led to more intuitive models like HSL (Hue, Saturation, Lightness), which map more closely to how artists and designers perceive and manipulate color.

Meanwhile, in the ink-and-paper world, the rules were completely different. On a screen, you start with black and add light (an additive model). On paper, you start with white and subtract light with ink (a subtractive model). This required its own language: CMYK (Cyan, Magenta, Yellow, Key/Black), the standard for printing.

The core problem, then, is translation. A designer needs to communicate a specific brand color to a web developer, who then needs to ensure that color looks right on a screen, and a print shop needs to ensure it looks right on a business card. Color models and the converters between them are the universal translators that make this possible, preventing a world of digital and physical design chaos.

How it works under the hood

At its heart, a color converter is a set of mathematical formulas that translate a value from one coordinate system to another. Think of it like converting Fahrenheit to Celsius—different scales for the same physical reality.

RGB: The Additive Primary School

This is the bedrock of all screen color. It defines a color by how much Red, Green, and Blue light are mixed together.

  • Model: rgb(red, green, blue)
  • Values: Each channel is an integer from 0 (none of that color) to 255 (the maximum amount).
  • How it works: It's an additive model. The starting point is black rgb(0, 0, 0). Adding all colors at full intensity gives you white rgb(255, 255, 255).
Color RGB Value Logic
Red rgb(255, 0, 0) Max red, no green or blue.
Green rgb(0, 255, 0) Max green, no red or blue.
Purple rgb(128, 0, 128) Medium red, no green, medium blue.
Gray rgb(128, 128, 128) Equal parts of all three, at medium intensity.

HEX: RGB's Shorthand Alias

HEX (Hexadecimal) codes are not a different color model; they are just a different way of writing RGB values. They're popular in HTML and CSS because they're more compact.

  • Model: #RRGGBB
  • How it works: Each two-character pair represents the Red, Green, and Blue channel values from RGB, but converted into hexadecimal (base-16). In hexadecimal, digits run from 0 to F (where A=10, B=11, ..., F=15). 00 is 0 in decimal, and FF is 255.
// Converting rgb(255, 99, 71) to HEX

// Red channel: 255
// 255 / 16 = 15 with remainder 15
// In hex, 15 is 'F'. So, 255 = FF

// Green channel: 99
// 99 / 16 = 6 with remainder 3
// In hex, 6 is '6', 3 is '3'. So, 99 = 63

// Blue channel: 71
// 71 / 16 = 4 with remainder 7
// In hex, 4 is '4', 7 is '7'. So, 71 = 47

// Result: #FF6347

A three-digit shorthand like #F0C is just a shortcut for #FF00CC.

HSL & HSV: The "Human-Friendly" Models

HSL (Hue, Saturation, Lightness) and HSV (Hue, Saturation, Value) were designed to be more intuitive.

  • Hue: The "color" itself, represented as an angle on a color wheel (0-360 degrees). 0° is red, 120° is green, 240° is blue.
  • Saturation: The intensity or "purity" of the color (0-100%). 0% is grayscale, 100% is the most vivid version of the hue.
  • Lightness (HSL) / Value (HSV): This is where they differ.
    • Lightness (HSL): A scale from black to the pure color to white. 0% is always black, 100% is always white, and 50% is the "purest" color.
    • Value (HSV): A scale from black to the pure color. 0% is always black, but 100% is the brightest, most saturated version of the color.

This distinction is crucial. In HSL, a fully saturated blue with 100% lightness is white. In HSV, a fully saturated blue with 100% value is bright blue. HSV is often preferred by digital artists for color picking, while HSL is common in CSS.

CMYK: The Print World's Subtractive Cousin

This model is for ink on paper. You start with a white surface and subtract brightness.

  • Model: cmyk(cyan, magenta, yellow, key)
  • Values: Each ink is represented as a percentage from 0% to 100%.
  • How it works: In a perfect world, 100% of C, M, and Y would make black. In reality, impurities in ink produce a muddy brown. So, we add K (Key, which stands for black) for true blacks, sharp text, and to save on more expensive colored inks. Converting from RGB to CMYK is complex because the range of colors reproducible by ink (the "gamut") is smaller than what screens can display. A super-vibrant screen green might look duller in print because there's no ink combination that can replicate it.

OKLCH: The Modern, Perceptually Uniform Contender

The new kid on the block, designed to fix a major flaw in HSL. The problem with HSL is that a 10% change in "Lightness" for a yellow and a blue results in a vastly different perceived change in brightness. Our eyes are more sensitive to yellow than blue.

OKLCH is "perceptually uniform." This means that a change in any of its values looks like an equally significant change to the human eye, regardless of the hue.

  • L (Lightness): How light the color appears (0-100%). Much more accurate than HSL's Lightness.
  • C (Chroma): How colorful the color is (similar to Saturation).
  • H (Hue): The angle on the color wheel (0-360).

This makes it incredible for creating smooth, natural-feeling color palettes and gradients. You can pick two colors and find the steps between them in OKLCH space, and the result will look much more even than doing the same in RGB or HSL.

Real-world stories

The Case of the Muddy Brand Palette

A designer was building a UI kit for a new app. Their brand color was a lovely, vibrant purple, hsl(265, 80%, 50%). To create tints and shades for hover states and borders, they simply adjusted the Lightness value up and down by 10%. The lighter colors looked great, but the darker shades looked... off. They became grayish and lost their purple "feel," looking almost like a different color entirely. The team was confused why the colors felt so disconnected.

The lesson: HSL is not perceptually uniform. Decreasing "Lightness" doesn't just make a color darker; it can also make it appear less saturated, pulling it towards gray. For creating harmonious color scales, using a perceptually uniform space like OKLCH or manually adjusting saturation along with lightness is the professional's move.

The Print vs. Web Fiasco

A tech conference designed its entire digital presence—website, app, social media—around a stunning, electric lime green (#04FF00). It was energetic and screamed "tech-forward." For the event, they ordered thousands of dollars worth of banners, lanyards, and t-shirts using the same HEX code. When the boxes arrived, disaster. The vibrant lime green had become a dull, washed-out pea green. It looked cheap and completely missed the energetic vibe.

The lesson: The RGB/HEX color space of screens has a wider gamut (range of colors) than the CMYK space of printers. That electric lime green simply did not exist in the world of ink. Always convert your colors to the target medium's color model (CMYK for print) and check a physical proof before a mass production run. Don't trust your screen to tell you what ink will look like.

The Accessible Button Crisis

A junior front-end developer was tasked with building a new settings page. Following the design mockups, they created a sleek interface with light gray buttons (#E0E0E0) containing white icons. It looked clean and minimalist on their high-contrast monitor. The code was pushed to production. A week later, support tickets started rolling in. Users were complaining they couldn't see the icons on the buttons. The color combination had a very low contrast ratio, making it illegible for users with visual impairments and difficult for anyone on a low-quality screen or in bright sunlight.

The lesson: Color is a core component of accessibility. Your personal perception of contrast is not a reliable metric. Always use a tool to check the contrast ratio between foreground and background colors against WCAG (Web Content Accessibility Guidelines) standards. Converting colors to a model like HSL or OKLCH can make it easier to find a compliant alternative by methodically adjusting lightness or chroma.

Common mistakes and traps

  • Thinking HEX is a unique color model. It's not. It's just a compact, base-16 representation of RGB. #FFFFFF is identical to rgb(255, 255, 255).
  • Using CMYK values in CSS. Don't do color: cmyk(0, 100, 100, 0). While some browsers might make a guess, it's not a web standard. Always provide web-native color formats like HEX, RGB, HSL, or OKLCH.
  • Creating color scales by only changing HSL's 'L'. This is the classic path to a palette with uneven perceptual brightness. Your yellows will look much brighter than your blues, even with the same 'L' value.
  • Assuming screen colors will print perfectly. The most common source of disappointment in branding. The RGB gamut is wider than the CMYK gamut. What you see is not always what you get on paper.
  • Mixing up HSL and HSV. They are similar but their Lightness/Value scales behave differently, especially at the extremes. A script that manipulates HSL values will produce different results than one that manipulates HSV, which can lead to subtle but frustrating bugs in color generation logic.

Why it belongs on your radar

If you write a single line of CSS, design a UI, create a data visualization, or put a brand's logo on anything, you're working with color models. Understanding them isn't just academic trivia; it's a fundamental skill for creating effective, accessible, and consistent user experiences.

You should think about color models when:

  • Implementing a design system and defining brand colors.
  • Creating themes (e.g., light mode/dark mode).
  • Ensuring your UI meets accessibility contrast requirements.
  • Programmatically generating charts, gradients, or palettes.
  • Collaborating with designers or print shops to ensure color consistency across media.

Knowing how to convert hsl(210, 50%, 95%) (a light blue background) to its HEX equivalent for a legacy system, or understanding why your brand's rgb(0, 255, 127) spring green needs to be adjusted for a CMYK brochure, is the mark of a well-rounded developer who can bridge the gap between design intent and technical reality.

Go deeper

  • MDN: <color> - The ultimate web developer reference for all CSS color types, including syntax and browser compatibility.
  • W3C CSS Color Module Level 4 - The official specification that defines color syntax in modern CSS, including new models like LCH and OKLCH.
  • Wikipedia: Color model - A comprehensive overview of the theory behind dozens of color models.
  • OKLCH, explained - A fantastic, interactive explanation of why OKLCH exists and how it improves on older color models.
  • Google Material Design: Understanding color - A practical guide to color theory and application in UI design from a major design system.

Theory done. Time to get your hands dirty — 100% in your browser.

Try the tool: Color Picker & Converter