Color Picker Tools for Developers: HEX, RGB, HSL, and CSS Custom Properties in 2026
Use color picker tools effectively in web development. HEX/RGB/HSL conversion, CSS theming with custom properties, WCAG contrast checking, and palette generation.
Color Picker Tools for Developers: HEX, RGB, HSL, and CSS Custom Properties in 2026
The Three Color Formats
| Format | Syntax | Use Case |
|---|---|---|
| HEX | #ff5733 | CSS, design tools |
| RGB | rgb(255, 87, 51) | JavaScript, Canvas |
| HSL | hsl(14, 100%, 60%) | Intuitive manipulation |
Converting Between Formats
// HEX β RGB
function hexToRgb(hex) {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
// RGB β HEX
function rgbToHex(r, g, b) {
return "#" + [r, g, b].map(x => x.toString(16).padStart(2, '0')).join('');
}
// RGB β HSL
function rgbToHsl(r, g, b) {
r /= 255; g /= 255; b /= 255;
const max = Math.max(r, g, b), min = Math.min(r, g, b);
let h, s, l = (max + min) / 2;
if (max === min) {
h = s = 0;
} else {
const d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch (max) {
case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break;
case g: h = ((b - r) / d + 2) / 6; break;
case b: h = ((r - g) / d + 4) / 6; break;
}
}
return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) };
}
CSS Custom Properties for Theming
:root {
/* Base colors */
--color-primary: hsl(210, 100%, 50%);
--color-secondary: hsl(160, 100%, 40%);
--color-background: hsl(0, 0%, 100%);
--color-text: hsl(0, 0%, 10%);
/* Dark mode */
@media (prefers-color-scheme: dark) {
:root {
--color-background: hsl(220, 20%, 10%);
--color-text: hsl(0, 0%, 95%);
}
}
}
/* Usage */
.button {
background: var(--color-primary);
color: white;
}
Accessibility: Contrast Checking
// WCAG 2.1 contrast ratio
function contrastRatio(color1, color2) {
const lum1 = relativeLuminance(color1);
const lum2 = relativeLuminance(color2);
const lighter = Math.max(lum1, lum2);
const darker = Math.min(lum1, lum2);
return (lighter + 0.05) / (darker + 0.05);
}
function relativeLuminance(hex) {
const rgb = hexToRgb(hex).map(c => {
c /= 255;
return c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
});
return 0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2];
}
// WCAG requirements
// AA: 4.5:1 for normal text
// AAA: 7:1 for normal text
// AA: 3:1 for large text (18pt+)
Generating Palettes Programmatically
function generatePalette(baseColor, steps = 5) {
const hsl = hexToHsl(baseColor);
return Array.from({ length: steps }, (_, i) => {
const lightness = 10 + (i * (80 - 10) / (steps - 1));
return `hsl(${hsl.h}, ${hsl.s}%, ${lightness}%)`;
});
}
// Example: generate 5 shades of blue
generatePalette('#3b82f6');
// ['hsl(217, 91%, 60%)', 'hsl(217, 91%, 70%)', ...]
Color Picker Tools
Use browser-based color pickers that show HEX, RGB, and HSL simultaneously, plus a contrast checker against white and black backgrounds.
Real-World Scenario
A design system needs a brand color #3b82f6 (blue) with 9 tonal steps β 50, 100, 200, 300, 400, 500, 600, 700, 800 β like Tailwind CSS generates. Doing this by hand in a design tool is slow and produces inconsistent results because designers tend to eyeball the steps rather than computing them mathematically. By converting the brand color to HSL, keeping the hue fixed, and interpolating the lightness value across 9 stops while also adjusting saturation slightly at the extremes, you get a perceptually uniform scale that works for both light and dark mode surfaces. The generatePalette function above is the starting point; real systems add a saturation curve so the mid-tones stay vivid while the near-white and near-black ends desaturate naturally.
Accessibility audits are another high-leverage use case for programmatic color work. Many teams discover accessibility failures during QA or worse, after a compliance complaint β because text color was chosen by a designer who looked good on their calibrated monitor but never ran a WCAG contrast check. Automating contrast checks in your design token build step catches these issues before they reach production. You can write a simple Node.js script that iterates over every foreground/background color pair in your token file, computes the contrast ratio, and fails the build if any combination falls below the 4.5:1 AA threshold for normal text. This turns a manual audit into a continuous enforcement gate.
Brand refresh projects frequently involve changing a single primary color, then needing every derived color β hover states, focus rings, disabled states, border colors β to update consistently. If your CSS uses raw HEX values scattered across dozens of files, this becomes a find-and-replace nightmare. If you use CSS custom properties with a structured naming convention (--color-primary-500, --color-primary-600, etc.) and generate the scale programmatically from a single source hue, a brand color change becomes a one-line update to your token source file. The entire derived scale regenerates automatically on the next build.
Quick Tips
-
Work in HSL when manipulating colors programmatically. HSL maps to human perception: hue is the color, saturation is the intensity, lightness is how bright it is. Generating hover states by reducing lightness by 10%, or disabled states by desaturating to 20%, produces predictable results. Doing the same math in RGB is not intuitive and leads to unexpected shifts.
-
Define all colors as CSS custom properties, even in small projects. When a brand color needs to change, you want to update it in one location. CSS variables cost nothing at runtime, and any modern browser or CSS preprocessor supports them. Start with
--color-primary,--color-surface,--color-text, and--color-borderas your baseline token set. -
Check contrast for every text/background combination before shipping. Use the WCAG contrast ratio formula or a tool like the browser DevTools accessibility panel. The minimum threshold is 4.5:1 for normal text (AA level). Do not assume that dark-on-light is always safe β a light grey text on a white background fails even though it looks readable on a bright monitor.
-
Use the browserβs native color picker for quick sampling. Chrome and Firefox DevTools both include a built-in color picker that activates when you click any color swatch in the Styles panel. It shows the HEX, RGB, and HSL values simultaneously and lets you switch between formats with one click β faster than any online tool for quick one-off checks.
-
Store your color tokens in a single JSON file and generate CSS variables from it. Tools like Style Dictionary can take a
tokens.jsonwith your color values and output CSS custom properties, Sass variables, iOS color assets, and Android resources from the same source. This eliminates format drift between platforms and makes a rebrand a single-source update rather than a multi-file surgery.
50 CLI Commands That Save Hours Every Week
The exact Git shortcuts, file search tricks, Docker commands, and productivity hacks that senior developers use daily. Compiled from 5+ years of shipping production code.
- Git mastery (10 cmds)
- File & search wizardry
- Docker & DevOps tricks
- Process & network tools
- Productivity boosters
- macOS & Linux install guide
No spam. 1 email/week max. Unsubscribe anytime.
Found this guide useful? Check out our free developer tools.
Affiliate disclosure: Some links below are affiliate links β we may earn a small commission at no extra cost to you. Learn more.
Recommended Tools & Resources
DigitalOcean
$200 credit for new users. Simple, affordable cloud hosting for developers.
GitHub Student Pack
Free access to 100+ developer tools. Perfect for students and new devs.
Vercel
Deploy frontend apps instantly. Free tier is generous for side projects.
DevPlaybook Products
Boilerplates, scripts & AI toolkits to 10x your dev workflow.