Color Theory for Developers
I used to pick colors by opening a color picker and clicking around until something looked "fine." Then I'd show it to a designer friend and watch them wince.
Turns out, color isn't random. There are actual rules, or at least strong guidelines. That make some combinations work and others clash. Once you learn them, you'll never look at UI the same way.
The Basics: Hue, Saturation, Lightness
Forget RGB and hex codes for a minute. When thinking about color, HSL (Hue, Saturation, Lightness) is way more intuitive.
Hue is the actual color - red, blue, green, whatever. It's measured in degrees on a color wheel, 0-360.
Saturation is intensity. 100% is vivid and punchy. 0% is gray. Most UI colors sit between 40-80% saturation. Fully saturated colors are aggressive and hard to look at for long.
Lightness is how light or dark the color is. 0% is black, 100% is white, 50% is the "pure" color.
Why does this matter? Because when you need variations of a color - hover states, disabled states, backgrounds. You adjust saturation and lightness, not hue. That's how you get colors that feel related instead of random.
Building a Color Palette
Every UI needs at least these colors:
- Primary - Your brand color, used for main actions
- Secondary - Supporting color for less important elements
- Neutral - Grays for text, backgrounds, borders
- Success - Green, for positive feedback
- Warning - Yellow/orange, for caution
- Error - Red, for problems
For each of these, you need multiple shades. Typically 9-11 steps from nearly white to nearly black. The 500 shade is usually your "base" color, with lighter shades (100-400) for backgrounds and darker shades (600-900) for text and borders.
Picking Your Primary Color
If you have brand guidelines, you're set. If not, here's a trick: go to a site like colorhunt.co or coolors.co and browse palettes. Find ones that feel right for your project's vibe. Techy? Blues and purples. Friendly? Oranges and greens. Premium? Deep navy or black with gold accents.
Once you have a primary, you can generate the rest systematically.
Generating Shades
Don't just add white or black to create shades. That makes colors look muddy and dead.
Instead, as colors get lighter: decrease saturation slightly and shift hue toward a warmer or cooler anchor. As colors get darker: increase saturation and shift hue the opposite direction.
Tools like tailwindcss.com/docs/customizing-colors have great example palettes. Or use a generator like uicolors.app - input your base color, get a full scale.
Contrast: The Non-Negotiable Rule
This is where most developers mess up. Color contrast isn't just aesthetic - it's accessibility.
WCAG guidelines require:
- 4.5:1 contrast ratio for normal text
- 3:1 for large text (18px+ or 14px+ bold)
- 3:1 for UI components and graphics
Check your contrast with tools like webaim.org/resources/contrastchecker. If it fails, adjust lightness until it passes.
Common failure: light gray text on white backgrounds. It might look "elegant" but it's unreadable for millions of people with vision impairments. Don't do it.
Color Relationships That Work
Here's where color theory gets interesting. Certain color combinations are naturally harmonious because of their positions on the color wheel.
Complementary: Colors opposite each other on the wheel (red/green, blue/orange). High contrast, high energy. Use sparingly - one as primary, the other as accent.
Analogous: Colors next to each other (blue, blue-green, green). Low contrast, harmonious. Good for creating cohesive, calm interfaces.
Triadic: Three colors equally spaced (red, yellow, blue). Vibrant but balanced. Tricky to pull off, usually best to make one dominant and use the others as accents.
Split-complementary: One color plus the two colors adjacent to its complement. Easier than straight complementary, still has pop.
For most UI work, I'd recommend: pick your primary, use analogous colors for variations, and add a complementary accent for CTAs that need to stand out.
The 60-30-10 Rule
Interior designers use this, and it works for UI too.
60% of your interface should be your dominant color, usually a neutral (white, light gray, dark gray in dark mode).
30% should be your secondary color - often your primary brand color at lower saturation for backgrounds, cards, sections.
10% should be your accent color - high-impact elements like primary buttons, links, important icons.
This creates visual hierarchy automatically. The 10% pops because it's rare.
Dark Mode: Not Just Invert
Flipping your colors to make dark mode doesn't work. White becomes black, sure, but colors behave differently on dark backgrounds.
On dark backgrounds:
- Saturated colors look more intense - tone them down
- Pure white (#FFFFFF) is harsh - use off-whites like #E0E0E0
- You need more contrast between surface layers
- Shadows don't work the same - use lighter overlays or borders instead
Test your color palette on both light and dark backgrounds. You might need different shades for each mode.
Practical Tips I Wish I'd Learned Earlier
Never use pure black. #000000 is harsh. Use #1A1A1A or similar for text. It's softer on the eyes and feels more natural.
Add a slight hue to your grays. Warm grays (tinted toward yellow/red) feel friendlier. Cool grays (tinted toward blue) feel more professional. Match it to your brand.
Use opacity for variations. Instead of picking 10 different grays, use your text color at different opacities. rgba(0, 0, 0, 0.87) for primary text, rgba(0, 0, 0, 0.6) for secondary, rgba(0, 0, 0, 0.38) for disabled.
Test with color blindness simulators. About 8% of men have some form of color blindness. Don't rely on color alone to convey meaning. Use icons, patterns, or text too.
Steal from the best. Find sites you admire, inspect their colors, understand why they work. This is how you develop taste faster than any theory can teach.
Your Color Checklist
Before shipping, ask yourself:
- Does all text meet contrast requirements?
- Can users understand the UI without seeing colors?
- Is there clear visual hierarchy?
- Does the palette feel cohesive?
- Have I tested on both light and dark backgrounds?
Color isn't magic. It's learnable. And once you understand the basics, you'll stop guessing and start making intentional choices that actually work.