RGB vs. HSL: Two Ways to Tell a Computer 'Color'

RGB tells a computer how to mix light (Red, Green, Blue), while HSL describes color how humans perceive it (Hue, Saturation, Lightness). Use RGB for brand colors and HSL for intuitive variations. The footgun is creating low-contrast UIs that are unreadable.
Why it exists
Computers and humans think about color differently. Computers create color by mixing red, green, and blue light on a screen. Humans perceive color based on its hue, intensity, and brightness. Digital color models provide a structured language to bridge this gap, letting us tell the computer what to display in a predictable way.
The mental model
RGB is for the machine. It's a technical recipe: "mix 214 parts red, 122 parts green, and 127 parts blue." HSL is for the human. It's an intuitive description: "start with a reddish-pink hue, make it pretty saturated, and keep it medium-light." HSL makes it easy to guess what a color will look like and to create variations, like a lighter shade for a hover effect.
How it works
In CSS, RGB is written as rgb(red, green, blue), where each value is 0-255. For example, rgb(214, 122, 127) is a dusty rose. HSL is written as hsl(hue, saturation, lightness). Hue is a degree on the color wheel (0-360), while saturation and lightness are percentages (0%-100%). For example, hsl(30, 82%, 43%) is a deep orange. Both models also support an optional alpha (transparency) channel, from 0 (fully transparent) to 1 (fully opaque).
When to use it
Use RGB when you have an exact color value from a design spec, often provided as a hex code (like #D67A7F), which is just shorthand for RGB. Use HSL when you need to create color systems or themes programmatically. For example, you can easily create a palette by keeping the hue the same and changing the saturation and lightness values. This is great for generating button states (default, hover, active).
When not to use it
Don't rely solely on visual intuition when picking colors, especially for text. The most common error is creating a design with insufficient contrast between the text and its background. This makes your content difficult or impossible for people with low vision to read and fails Web Content Accessibility Guidelines (WCAG). Always use a contrast checker tool.
One canonical example
A button needs a background color and a slightly lighter hover state. Using HSL, you could define the base color as hsl(237, 74%, 33%) (a deep blue). For the hover state, you can simply increase the lightness to hsl(237, 74%, 43%). Trying to calculate the "10% lighter" version of the equivalent RGB color, rgb(21, 33, 142), is much harder and less intuitive.
Interview question
Which scenario best highlights HSL's primary advantage over RGB in UI design?
- a.Confirming that text color provides adequate contrast against its background.
- b.Programmatically generating a consistent color palette with varying lightness for UI states.Correct
- c.Ensuring a color exactly matches a corporate brand's hexadecimal specification.
- d.Defining a color by its precise red, green, and blue light component values.
Why? this is the answer
HSL's intuitive structure (Hue, Saturation, Lightness) makes it ideal for creating systematic color variations, such as lighter shades for hover states, by simply adjusting the lightness. RGB is better suited for precise color matching from exact specifications like hex codes, rather than generating variations.
Just read this? Test yourself on what you have been reading.
Read the original → developer.mozilla.org
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on css — each one lists the topics its interview covers.
See open roles