Building a Custom Tailwind Color Palette That Actually Works
Tailwind's built-in colors are good, but every serious project needs its own brand colors. Here's how to generate a proper shade scale, add it to your config, and make it work seamlessly with dark mode — without producing an ugly palette by accident.
How Tailwind's Color System Works
Tailwind's default colors each have eleven shades numbered 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, and 950. The number is a rough lightness index: 50 is near-white, 950 is near-black.
This scale isn't linear. The perceptual difference between consecutive shades is deliberately compressed at the light end and expanded at the dark end — because human vision is more sensitive to lightness differences at low luminance. A visually even scale requires unequal lightness steps. This is the source of most failed custom palette attempts: people generate a linear scale and wonder why it looks wrong.
Choosing Your Base Color
Start with one color — your brand primary. This becomes your 500 shade. It should be saturated enough to read as clearly colored, with HSL lightness between 45–60%. Below 45%, your lighter shades won't have enough range. Above 60%, your darker shades lose punch. The 500 is your anchor; everything else scales from it.
One pitfall: choosing a brand color that's too desaturated. A muted sage green looks refined on a landing page but produces a washed-out, indistinct Tailwind scale. Bump saturation 15–20% before generating the scale, then dial individual shades back as needed.
How a Good Scale Is Generated
- Convert your base color to HSL.
- Apply preset lightness targets: 50 → ~97%, 100 → ~94%, 200 → ~88%, down to 900 → ~15%, 950 → ~9%.
- Adjust saturation per shade — lighter shades get reduced saturation (to avoid looking washed out); darker shades may get a small boost.
- Optionally shift hue 2–5° across the scale, mimicking how physical pigments behave in light and shadow.
The result looks natural because it follows the same perceptual principles as Tailwind's built-in palettes.
Adding Colors to tailwind.config.js
Always use theme.extend.colors, not theme.colors directly. Extending preserves Tailwind's defaults (slate, zinc, emerald, etc.) alongside your custom colors. Writing directly to theme.colors replaces them entirely.
The DEFAULT key: Add DEFAULT: '#7c6af7' inside your color object to make bg-brand work without a shade number — useful for component APIs where you want a sensible fallback.
Dark Mode with CSS Variables (the Right Pattern)
Hard-coded hex values work for single-theme projects. For dark mode, use CSS variables: define different values per theme in your global CSS, then reference them in Tailwind config. This lets a single text-brand-500 class automatically adapt between themes without needing dark:text-brand-400 everywhere.
The format Tailwind expects for CSS variable colors is space-separated RGB channels (no hash, no rgb() wrapper), so the opacity modifier — text-brand-500/50 — continues to work correctly.
Common Shade Usage Patterns
- 50–100: Page backgrounds, subtle tinted surfaces.
- 200–300: Borders, dividers, inactive states.
- 400–500: Primary interactive elements — buttons, links, focus rings.
- 600–700: Hover states, pressed states, stronger borders.
- 800–900: Dark surfaces, sidebar backgrounds, code blocks.
- 950: Near-black for maximum contrast text on light backgrounds.
Resist the urge to use your brand color for everything. Shades 100–300 exist precisely to give you a palette that reads as "branded" without every element competing for attention. Use 50–200 for backgrounds and your 500–600 for interactive elements — everything reads as one coherent system.
Checking Contrast Before You Commit
Before finalizing your scale, verify that white text on your 500+ shades and dark text on your 50–400 shades meet 4.5:1 WCAG AA contrast. A beautiful palette that fails accessibility is a palette you'll have to revise after shipping. The breakpoint is usually somewhere between 400 and 600 — check both directions.
Generate Your Tailwind Palette
Enter any base color and get a full 50–950 scale in Tailwind config format, ready to paste.
Open Palette Builder →