You open your CSS file. You type color: #3b82f6;. It works. But do you actually know what that number means?

Most developers copy colors from Figma, Tailwind docs, or color picker tools. They don't understand why certain colors work and others clash.

But once you understand color theory — HEX, RGB, HSL, and how they relate — you can:

  • Build your own color palettes
  • Create dark mode themes easily
  • Fix contrast issues without guessing
  • Make accessible UI that meets WCAG standards

In this guide, I'll explain color theory in plain English for developers. No design degree needed. Just practical knowledge you can apply today.

Want to pick colors right now? Use our free color picker — HEX, RGB, HSL, and more.

What Is Color, Really? (In Simple Words)

Every color on your screen is made of three lights: Red, Green, and Blue.

Your screen is not made of "paint." It's made of tiny lights. When all three lights are at full brightness, you see white. When all three are off, you see black.

Mix red and green? You get yellow. Mix red and blue? Magenta. Mix green and blue? Cyan. All three? White.

This is called RGB color model. Every color you see on a screen is a mix of these three primary colors.

The Three Main Color Formats

There are three ways to represent a color in code. Let's look at each.

1. HEX (Hexadecimal)

Example: #3b82f6

HEX is the most common format in web development. It's a 6-digit code with a # prefix.

How to read it:

  • First 2 digits = Red
  • Next 2 digits = Green
  • Last 2 digits = Blue

Each pair is a number from 00 to ff (0 to 255 in decimal). So #3b82f6 means:

  • Red: 3b = 59
  • Green: 82 = 130
  • Blue: f6 = 246

Common HEX colors:

HEX Color Notes
#000000BlackShortcut: #000
#ffffffWhiteShortcut: #fff
#ff0000RedFull red
#00ff00GreenFull green
#0000ffBlueFull blue
#3b82f6Tailwind blue-500Very common

2. RGB (Red, Green, Blue)

Example: rgb(59, 130, 246)

RGB is the same as HEX but in decimal. Each value is from 0 to 255.

#3b82f6 = rgb(59, 130, 246) — same color, different format.

When to use RGB:

  • When you need transparency — rgba(59, 130, 246, 0.5) (50% opacity)
  • When calculating colors in JavaScript
  • When mixing colors programmatically

3. HSL (Hue, Saturation, Lightness)

Example: hsl(217, 91%, 60%)

HSL is the most human-friendly format. It matches how we think about color.

  • Hue (0-360): The color itself. 0 = red, 120 = green, 240 = blue.
  • Saturation (0-100%): How vivid the color is. 0% = gray, 100% = pure color.
  • Lightness (0-100%): How bright. 0% = black, 50% = normal, 100% = white.

#3b82f6 = hsl(217, 91%, 60%) — same color again.

Why HSL is powerful:

Want a lighter version of your brand color? Just increase lightness.

hsl(217, 91%, 40%) → dark blue
hsl(217, 91%, 60%) → normal blue
hsl(217, 91%, 80%) → light blue

Want a muted version? Decrease saturation.

hsl(217, 100%, 60%) → vivid blue
hsl(217, 50%, 60%) → muted blue
hsl(217, 10%, 60%) → grayish blue

Try doing that with HEX. It's much harder. This is why modern design systems use HSL.

The Color Wheel: Understanding Relationships

The color wheel is your best friend. It shows how colors relate to each other.

Primary Colors

Red, Yellow, Blue. They can't be made by mixing others.

Secondary Colors

Green (yellow + blue), Orange (red + yellow), Purple (red + blue).

Tertiary Colors

Colors between primary and secondary — like teal, amber, magenta.

Color Schemes (Practical for UI)

1. Monochromatic: One hue, different lightness/saturation.

hsl(217, 91%, 20%)
hsl(217, 91%, 40%)
hsl(217, 91%, 60%)
hsl(217, 91%, 80%)

Clean, professional. Great for business apps.

2. Complementary: Two colors opposite on the wheel.

Example: Blue + Orange. Great for CTA buttons that pop.

3. Analogous: Colors next to each other on the wheel.

Example: Blue + Purple + Teal. Calm, cohesive look.

4. Triadic: Three colors evenly spaced (120° apart).

Example: Red + Yellow + Blue. Bold, playful, energetic.

For most UIs, monochromatic or analogous palettes work best. Reserve complementary and triadic for accents.

Building a Color Palette (Real Example)

Let's build a color system for a SaaS dashboard using HSL.

Step 1: Pick a primary hue. Let's use 217 (a blue).

Step 2: Create shades.

Name HSL Use Case
blue-50hsl(217, 91%, 97%)Backgrounds
blue-100hsl(217, 91%, 92%)Hover states
blue-300hsl(217, 91%, 76%)Borders
blue-500hsl(217, 91%, 60%)Primary buttons
blue-700hsl(217, 91%, 40%)Pressed state
blue-900hsl(217, 91%, 20%)Headings

Step 3: Add semantic colors.

  • Success (green): hsl(142, 71%, 45%)
  • Warning (yellow): hsl(38, 92%, 50%)
  • Error (red): hsl(0, 84%, 60%)
  • Info (blue): Same as primary

Step 4: Add neutrals.

  • Gray scale: hsl(220, 9%, 46%) variations
  • Dark mode: Flip lightness (dark backgrounds, light text)

That's a complete palette. From this, you can build entire UIs.

Accessibility: Contrast Matters

Choosing a pretty color isn't enough. Users must be able to read it.

The WCAG (Web Content Accessibility Guidelines) defines minimum contrast ratios:

  • AA (minimum): 4.5:1 for normal text, 3:1 for large text
  • AAA (enhanced): 7:1 for normal text, 4.5:1 for large text

Bad example:

Light gray text #cccccc on white #ffffff
Contrast ratio: 1.6:1 ❌ Fails WCAG

Good example:

Dark gray text #333333 on white #ffffff
Contrast ratio: 12.6:1 ✅ Passes AAA

Tools to check contrast: WebAIM Contrast Checker, Chrome DevTools, Polypane.

Quick tip: if you can't read it easily while squinting, the contrast is too low.

Dark Mode: How to Do It Right

Dark mode isn't just "invert colors." Do that, and everything looks ugly.

Rules for good dark mode:

  • Don't use pure black (#000000). Use #0f0f0f or hsl(220, 15%, 10%).
  • Don't use pure white text. Use #e5e5e5 or hsl(220, 15%, 90%). Pure white on black is too harsh.
  • Reduce saturation. Bright colors look neon on dark backgrounds. Lower saturation by 20%.
  • Elevate with lightness. In light mode, shadows indicate elevation. In dark mode, use lighter backgrounds.
  • Test contrast again. Colors that worked in light mode may fail in dark mode.

Example dark mode palette:

Element Light Mode Dark Mode
Background#ffffff#0f172a
Surface#f9fafb#1e293b
Text#111827#e2e8f0
Muted text#6b7280#94a3b8
Primary#3b82f6#60a5fa

Color Psychology: What Colors Mean

Colors trigger emotions. Use them wisely in UI.

Color Feeling Common Use
🔵 BlueTrust, calm, professionalBanks, SaaS, healthcare
🔴 RedUrgency, danger, passionClearance, errors, food
🟢 GreenGrowth, success, natureFinance, eco, health
🟡 YellowHappy, warning, energyWarnings, kids apps
🟠 OrangeFriendly, confident, playfulCTAs, creative tools
🟣 PurpleLuxury, creative, mysticalPremium, beauty, tech
⚫ BlackPremium, serious, powerfulLuxury brands, fashion

Tip: Your primary button color should reflect your brand. But "danger" actions (delete, logout) should be red or dark. "Success" should be green.

Frequently Asked Questions

Should I use HEX or RGB or HSL?

For most cases: HEX for static colors, RGB when you need transparency (rgba), HSL when building color systems or dark mode. Modern browsers support all three.

What's the difference between #fff and #ffffff?

They're identical. When each RGB pair repeats (like ff, ff, ff), you can shorten it. #fff = #ffffff. Same for #000 = #000000.

How many colors should a UI have?

For most UIs: 1 primary, 1-2 accents, 4 semantic colors (success/warning/error/info), and 5-9 neutral grays. That's about 15-20 total. More than 25 becomes chaotic.

Is pure black (#000000) bad for dark mode?

Yes. Pure black causes eye strain and makes text harder to read. Use #0f0f0f or hsl(220, 15%, 8%) instead. Also avoid pure white text.

What's the ideal contrast ratio?

Minimum 4.5:1 for normal text (WCAG AA). 7:1 for AAA. For large text (18px+ or 14px bold), 3:1 is enough.

How do I pick a good brand color?

Consider: industry (blue for trust, orange for energy), competitors (be different), and audience (younger = brighter, older = muted). Test with real UI before committing.

Why do designers use HSL more than HEX?

Because HSL is more intuitive. Want a lighter shade? Increase lightness. Less saturated? Decrease saturation. With HEX, you'd need to recalculate manually.

What's the difference between opacity and transparency?

They're related but not the same. Opacity affects the entire element. Transparency in RGBA affects only the color. opacity: 0.5 affects text + background + border. rgba(0,0,0,0.5) only affects the color.

Final Words

Color theory sounds intimidating. But for developers, you only need to know three things:

  • HEX, RGB, HSL are just different ways to write the same color.
  • HSL is best for building color systems and dark mode.
  • Contrast matters more than beauty. If users can't read it, the color is wrong.

Once you understand these, you can build your own color palettes. No more copying from Figma blindly.

Want to pick colors right now? Use our free color picker — supports HEX, RGB, HSL, and gives you complementary colors instantly.

Pick Colors Like a Pro

Instant HEX, RGB, HSL conversion. Copy-paste ready. Free forever.