Color Picker
Interactive visual color picker. Drag the marker to choose saturation and brightness, use the hue slider for color.
Tints & Shades
Color on the web
Every color on a screen is a mixture of red, green and blue light. The various notations - HEX, RGB, HSL - are just different ways of writing the same mixture, and every one of them converts losslessly into the others.
Which you use is a question of what you are doing. HEX is compact and universal. RGB maps directly onto how the screen works. HSL is the one you can reason about intuitively, which makes it far better for building a color system.
Key takeaways
- HEX, RGB and HSL are interchangeable notations for the same color.
- HSL is the easiest to adjust by hand - change lightness to get a tint or shade.
- Contrast ratio, not color choice, determines accessibility.
- Aim for 4.5:1 contrast for body text and 3:1 for large text.
- Never use color alone to convey information.
The notations compared
| Format | Example | Strength | Weakness |
|---|---|---|---|
| HEX | #6366F1 | Compact, universally supported | Impossible to read by eye |
| RGB | rgb(99 102 241) | Maps to how screens work | Hard to adjust intuitively |
| RGBA | rgb(99 102 241 / 0.5) | Adds transparency | Same |
| HSL | hsl(239 84% 67%) | Intuitive to adjust | Perceptually uneven |
| HWB | hwb(239 39% 5%) | Natural for tints and shades | Less familiar |
| OKLCH | oklch(62% 0.21 275) | Perceptually uniform | Newer browser support |
OKLCH is worth knowing about: unlike HSL, equal changes in its lightness value look like equal changes to the eye, which makes generating a balanced palette far easier.
Understanding HSL
- Hue (0-360°) is the position on the color wheel. 0 is red, 120 green, 240 blue.
- Saturation (0-100%) is intensity. 0% is gray; 100% is fully vivid.
- Lightness (0-100%) runs from black at 0% through the pure hue at 50% to white at 100%.
This structure is why HSL is so useful in practice. To create a hover state, lower the lightness by ten points. To create a muted variant, lower the saturation. To find a complementary color, add 180 to the hue. None of those operations is remotely intuitive in HEX.
Color and accessibility
The Web Content Accessibility Guidelines define minimum contrast ratios between text and its background. These are not stylistic preferences - they are what makes text legible for people with low vision, and in bright sunlight for everyone.
| Content | WCAG AA | WCAG AAA |
|---|---|---|
| Body text | 4.5:1 | 7:1 |
| Large text (18pt+, or 14pt bold) | 3:1 | 4.5:1 |
| UI components and graphics | 3:1 | - |
| Decorative elements | No requirement | - |
Contrast ratios run from 1:1 (identical) to 21:1 (black on white). Most brand colors fail AA as text on white without darkening.
Color blindness
Around 8% of men and 0.5% of women have some form of color vision deficiency. The most common forms affect red-green discrimination.
- Never use color alone to convey meaning. Add an icon, a label, a pattern or a shape.
- Red and green are the worst pairing - precisely the one used for success and error states everywhere.
- Blue and orange is a far safer high-contrast pairing.
- Vary lightness as well as hue so a grayscale version remains distinguishable.
- Test by viewing your design in grayscale, which is a quick and surprisingly effective check.
CSS custom properties
Defining colors as CSS variables makes theming and maintenance far easier than scattering hex codes through a stylesheet:
--brand: #6366F1;
--brand-hover: #4F46E5;
--text: #1C1917;
}
.button { background: var(--brand); }
Because custom properties cascade, a dark theme becomes a matter of redefining the variables inside a media query or under a data attribute, rather than rewriting every rule.
Frequently Asked Questions
What is the difference between HEX, RGB and HSL?
They are three notations for the same color. HEX is a compact six-digit form, RGB states the red, green and blue components directly, and HSL uses hue, saturation and lightness. All convert losslessly between one another.
Which color format should I use in CSS?
HEX is fine for fixed values and is universally understood. HSL is better when you need to generate variations, because adjusting lightness or saturation is straightforward. OKLCH is worth adopting for new work, since it is perceptually uniform.
How do I create a lighter or darker version of a color?
Convert to HSL and change the lightness value. Raising it produces a tint, lowering it a shade, and keeping hue and saturation constant means the result still visibly belongs to the same family.
What contrast ratio do I need for accessibility?
WCAG AA requires 4.5:1 for body text and 3:1 for large text or UI components. AAA requires 7:1 for body text. Most brand colors fail AA as text on white without being darkened first.
Why is light gray text a problem?
Because it usually fails contrast requirements. #999999 on white gives about 2.85:1, well below the 4.5:1 minimum. It looks refined on a designer's calibrated monitor and is genuinely difficult to read for many people and in bright light.
How do I make colors work for color-blind users?
Never rely on color alone to convey meaning - add an icon, label or pattern. Avoid red-green as the only distinction, since that is the most common deficiency. Vary lightness as well as hue, and check your design in grayscale.
What are CSS custom properties for colors?
Variables defined once, typically on :root, and referenced throughout the stylesheet with var(). They make maintenance and theming far easier, since a dark theme becomes a matter of redefining the variables rather than rewriting every rule.
What is OKLCH and should I use it?
A newer color space that is perceptually uniform, meaning equal numeric changes look like equal visual changes. HSL does not have this property, which is why an HSL palette can look unevenly weighted. OKLCH is well supported in current browsers and makes generating balanced scales much easier.