Random Color Generator
Generate random colors with HEX, RGB, HSL, CMYK values. Create harmonious palettes with complementary, analogous, triadic, and monochromatic color schemes.
About
Color selection errors propagate through entire design systems. A wrong H (hue) shift of 15° in your primary palette can make complementary accents clash, reducing readability and increasing user bounce rates. This generator produces colors across all four major notation systems - HEX, RGB, HSL, and CMYK - and computes WCAG 2.1 contrast ratios against white and black backgrounds so you can verify accessibility compliance before committing to a palette. It implements seven harmony modes derived from color theory: complementary (H + 180°), analogous (H ± 30°), triadic, tetradic, split-complementary, and monochromatic variations.
The tool approximates perceptual uniformity by generating in HSL space rather than raw RGB, which avoids the dark muddy outputs typical of naive Math.random × 255 approaches. Saturation is bounded between 40% and 90%, lightness between 35% and 75% by default, filtering out near-white and near-black results. Limitation: CMYK values are calculated using a simple subtractive model without ICC color profiles, so printed output may differ from screen rendering.
Formulas
Color conversion between HSL and RGB uses a piecewise chroma-based calculation. The relative luminance formula from WCAG 2.1 determines whether a color meets accessibility contrast thresholds.
HSL to RGB conversion derives chroma C, then maps to an intermediate RGB triplet:
C = (1 − |2L − 1|) × SX = C × (1 − |(H ÷ 60) mod 2 − 1|)
m = L − C2
WCAG 2.1 relative luminance (L) for contrast ratio:
L = 0.2126Rlin + 0.7152Glin + 0.0722Blinwhere each linear channel value is:
Contrast ratio between two luminances:
CR = L1 + 0.05L2 + 0.05where L1 is the lighter luminance. A ratio ≥ 4.5 passes WCAG AA for normal text.
RGB to CMYK (simple subtractive, no ICC profile):
K = 1 − max(R′, G′, B′)C = 1 − R′ − K1 − K
where R′ = R ÷ 255 (normalized). Same pattern applies for M and Y channels.
Reference Data
| Harmony Mode | Hue Relationship | Swatch Count | Best For | Contrast Risk |
|---|---|---|---|---|
| Random | No constraint | 1 - 8 | Exploration, brainstorming | High (unchecked) |
| Complementary | H + 180° | 2 | CTA buttons, alerts | Low |
| Analogous | H ± 30° | 3 | Backgrounds, gradients | Medium (low contrast between swatches) |
| Triadic | H + 120°, + 240° | 3 | Vibrant illustrations | Low |
| Tetradic | H + 60°, + 180°, + 240° | 4 | Complex dashboards | Low |
| Split-Complementary | H + 150°, + 210° | 3 | Softer contrast than complementary | Low - Medium |
| Monochromatic | Same H, vary S/L | 5 | Elegant, minimal UI | High (similar tones) |
| WCAG 2.1 Contrast Ratio Thresholds | ||||
| AA Large Text | ≥ 3.0:1 | Text ≥ 18pt or 14pt bold | ||
| AA Normal Text | ≥ 4.5:1 | Body copy, labels | ||
| AAA Normal Text | ≥ 7.0:1 | Maximum readability | ||
| Common Color Space Ranges | ||||
| HEX | #000000 - #FFFFFF | 16,777,216 possible values | ||
| RGB | 0 - 255 per channel | Additive (screen) | ||
| HSL | H: 0 - 360°, S/L: 0 - 100% | Perceptual (human-intuitive) | ||
| CMYK | 0 - 100% per channel | Subtractive (print) | ||