🍋
Menu
How-To Beginner 1 min read 171 words

How to Build a CSS Color Palette Generator

Creating consistent color palettes is essential for design systems. Learn how to generate HSL-based palettes and CSS custom property scales.

Key Takeaways

  • HSL (Hue, Saturation, Lightness) is the most intuitive color model for palette generation.
  • A standard palette includes shades from 50 (lightest) to 950 (darkest), following the Tailwind CSS convention.
  • Map palette values to semantic tokens: `--color-primary`, `--color-danger`, `--color-success`.
  • OKLCH improves on HSL by producing perceptually uniform scales — each lightness step looks equally different to human eyes.
  • After generating a palette, verify that text/background combinations meet WCAG contrast requirements.

HSL: The Designer's Color Model

HSL (Hue, Saturation, Lightness) is the most intuitive color model for palette generation. By keeping hue constant and varying lightness from 5% to 95%, you create a consistent shade scale from darkest to lightest.

Generating a 10-Step Scale

A standard palette includes shades from 50 (lightest) to 950 (darkest), following the Tailwind CSS convention. Each step reduces lightness by roughly 8-10 percentage points.

Semantic Color Tokens

Map palette values to semantic tokens: --color-primary, --color-danger, --color-success. This abstraction lets you change the entire palette by updating a single hue value.

OKLCH: Better Perceptual Uniformity

OKLCH improves on HSL by producing perceptually uniform scales — each lightness step looks equally different to human eyes. HSL scales can appear uneven because human perception of lightness is nonlinear.

Accessibility Verification

After generating a palette, verify that text/background combinations meet WCAG contrast requirements. Light backgrounds need dark text (shade 900 on shade 50) and vice versa. Aim for at least 4.5:1 contrast ratio for normal text.

Herramientas relacionadas

Formatos relacionados

Guías relacionadas