Developer WorkflowsBy PaletteKey Team 7 min read

How to Generate Tailwind Color Scales with OKLCH

Learn to create perceptually uniform 50-950 color scales for Tailwind CSS using OKLCH. Includes v3 and v4 config exports, step-by-step guide, and visual comparisons.

Key Technical Takeaway

Tailwind CSS uses 50-950 color scales. Generating custom scales with OKLCH produces smooth, perceptually uniform steps across all hues for Tailwind v3 and v4.

How to Generate Tailwind Color Scales with OKLCH

Tailwind CSS revolutionized how developers work with color. Instead of writing custom CSS for every shade, you get a complete palette out of the box: slate, gray, zinc, red, orange, amber, and ten more hues, each with eleven steps from 50 to 950.

But what happens when you need to add your own brand colors?

Maybe your design system calls for a custom teal that does not exist in Tailwind’s default palette. Maybe you need a signature purple that matches your logo. Or maybe you are building a white-label product that needs to support multiple brand identities.

In all of these cases, you need a custom color scale. And if you generate that scale using HEX or HSL, you will run into the same old problem: uneven visual steps, unpredictable hover states, and colors that look wrong in dark mode.

This guide will show you how to generate custom Tailwind color scales using OKLCH, the perceptually uniform color space that produces smooth, consistent, and predictable results across every hue.

The Problem with HEX-Based Tailwind Scales

Let us say your brand color is a vibrant blue: #3B82F6. You want to generate a full 50-950 scale for Tailwind so you can use classes like bg-brand-500, text-brand-700, and hover:bg-brand-600.

The naive approach is to programmatically lighten and darken the HEX value. The result looks something like this:

  • brand-50: #EFF6FF (very light)
  • brand-100: #DBEAFE
  • brand-200: #BFDBFE
  • brand-300: #93C5FD
  • brand-400: #60A5FA
  • brand-500: #3B82F6 (base)
  • brand-600: #2563EB
  • brand-700: #1D4ED8
  • brand-800: #1E40AF
  • brand-900: #1E3A8A
  • brand-950: #172554 (very dark)

Why OKLCH Is Perfect for Tailwind Scales

OKLCH separates color into three perceptually meaningful dimensions: Lightness, Chroma, and Hue. When you generate a shade scale in OKLCH, you are adjusting the actual perceived brightness of the color, not just a mathematical value.

Let us look at the same brand blue (#3B82F6) converted to OKLCH and then scaled:

  • Base: oklch(62.3% 0.19 259.8)
  • brand-50: oklch(97% 0.02 259.8)
  • brand-100: oklch(93% 0.04 259.8)
  • brand-200: oklch(88% 0.07 259.8)
  • brand-300: oklch(80% 0.12 259.8)
  • brand-400: oklch(71% 0.16 259.8)
  • brand-500: oklch(62.3% 0.19 259.8)
  • brand-600: oklch(54% 0.17 259.8)
  • brand-700: oklch(45% 0.15 259.8)
  • brand-800: oklch(37% 0.12 259.8)
  • brand-900: oklch(29% 0.09 259.8)
  • brand-950: oklch(20% 0.06 259.8)

Understanding the 50-950 Naming Convention

Before we generate a scale, let us clarify what the numbers mean. Tailwind uses an 11-step scale: • 50: Lightest tint (Page backgrounds, subtle fills) • 100: Very light (Card backgrounds, hover states) • 200: Light (Borders, dividers, disabled states) • 300: Medium-light (Secondary text, placeholders) • 400: Medium (Icons, subtle accents) • 500: Base (Primary buttons, brand elements) • 600: Medium-dark (Button hover states) • 700: Dark (Active states, emphasis text) • 800: Very dark (Headings on light backgrounds) • 900: Darkest (High-contrast text) • 950: Deepest shade (Dark mode backgrounds, borders)

Step-by-Step: Creating a Custom Tailwind Color Scale

Step 1: Choose Your Base Brand Color Start with your brand’s primary color (e.g. teal #14B8A6).

Step 2: Generate the Full Scale Enter your base color into PaletteKey’s Tailwind Color Generator. The tool automatically converts your HEX to OKLCH, calculates perceptually uniform lightness steps, and outputs the full scale.

Step 3: Export for Tailwind v3:

// tailwind.config.js
module.exports = {
  theme: {
    extend: {
      colors: {
        brand: {
          50: "#f0fdfa",
          100: "#ccfbf1",
          200: "#99f6e4",
          300: "#5eead4",
          400: "#2dd4bf",
          500: "#14b8a6",
          600: "#0d9488",
          700: "#0f766e",
          800: "#115e59",
          900: "#134e4a",
          950: "#042f2e",
        }
      }
    }
  }
}

Step 4: Export for Tailwind v4 & Test

Tailwind v4 moves to a CSS-first configuration. The export looks like this:

/* styles.css */
@theme {
  --color-brand-50: oklch(97% 0.02 174);
  --color-brand-100: oklch(93% 0.05 174);
  --color-brand-200: oklch(88% 0.09 174);
  --color-brand-300: oklch(80% 0.14 174);
  --color-brand-400: oklch(72% 0.17 174);
  --color-brand-500: oklch(64% 0.19 174);
  --color-brand-600: oklch(55% 0.17 174);
  --color-brand-700: oklch(47% 0.15 174);
  --color-brand-800: oklch(39% 0.12 174);
  --color-brand-900: oklch(31% 0.09 174);
  --color-brand-950: oklch(22% 0.06 174);
}

Generate Your First OKLCH Tailwind Scale

You do not need to understand the math behind OKLCH to benefit from it. You just need a tool that handles the math for you.

PaletteKey’s Tailwind Color Generator takes any brand color and produces a complete, perceptually uniform 50-950 scale in seconds. Export to Tailwind v3 or v4 config, copy-paste into your project, and start building.

Frequently Asked Questions

What is the 50-950 naming in Tailwind?

Tailwind uses an 11-step scale where 50 is the lightest tint, 500 is the base color, and 950 is the darkest shade. This convention is standard across Tailwind, Material Design, and most modern CSS frameworks for consistent hover states and dark mode mapping.

Does Tailwind v4 support OKLCH?

Yes. Tailwind v4 uses a CSS-first configuration with @theme blocks that can store OKLCH values directly in CSS custom properties. The browser renders them without conversion.

Can I use OKLCH with Tailwind v3?

Yes, but the tailwind.config.js file stores HEX or RGB values. You can generate scales in OKLCH for perceptual accuracy, then convert the final output to HEX for the config. PaletteKey’s Tailwind Color Generator handles this conversion automatically.

Why are my HEX-based Tailwind scales uneven?

HEX and HSL do not model human perception. A 10% lightness drop in HSL produces different visual results for yellow versus blue. OKLCH ensures each step is perceptually uniform, so the scale looks smooth across all hues.

How many custom colors should a design system have?

Most systems use 1 to 3 brand colors plus 3 to 5 semantic colors such as success, warning, error, info, and neutral. Each color gets an 11-step scale. More than 8 custom colors usually creates visual noise and complicates maintenance.

What if my brand color is very light or dark?

The Tailwind Color Generator handles this automatically. If your base is already very light, the lighter steps compress into a narrow range and the darker steps expand. The perceptual spacing remains consistent regardless of the base color’s initial lightness.

How do I add custom colors to Tailwind v4?

In Tailwind v4, add CSS custom properties inside an @theme block in your CSS file. The Tailwind Color Generator exports the exact @theme code with your custom color name and all 11 steps.

What is the difference between primitive and semantic tokens?

Primitive tokens store raw color values like brand-500: #3B82F6. Semantic tokens describe usage like button-background: brand-500. For Tailwind, you typically work with primitive tokens in the config, then map them semantically in your components.

Should I use OKLCH or HEX for my Tailwind config?

Use OKLCH for Tailwind v4 where it is natively supported. For Tailwind v3, use HEX in the config but generate the scale in OKLCH first to ensure perceptual uniformity. The visual difference is significant, especially for hover states and dark mode.

Can I generate dark mode variants automatically?

Yes. When you generate a scale from a base color, the darker steps (600-950) naturally work as dark mode alternatives to the lighter steps (50-400). PaletteKey’s Design Token Generator can also create explicit light and dark mode semantic mappings.

Put Theory into Practice with Free Color Tools

Apply the concepts from this guide directly in your web workflow with our interactive tools.