Random Color Generator: Fair Colors and Palettes That Work
A random color generator should be able to land on any of the 16,777,216 sRGB colors, black and white included. Roll one fair color, a styled set or a harmony palette, and every swatch comes with paste-ready codes and the text color that reads on it.
Random color generator
0.05 is barely different, 0.12 is clearly different, 0.20 and up is very far apart.
Generated colors
History
The last 20 sets, kept only in this browser.
How the colors are drawn
Any color is one whole number from 0 to 16,777,215 taken from crypto.getRandomValues, so each of the 16,777,216 sRGB colors has the same chance, black, white and every grey included.
Styles draw lightness L, chroma C and hue h evenly inside these OKLCH ranges, keeping only colors sRGB can show:
| Style | Lightness L | Chroma C |
|---|---|---|
| Pastel | 0.84–0.94 | 0.03–0.08 |
| Vivid | 0.55–0.75 | 0.15–0.30 |
| Neon | 0.70–0.90 | 0.20 and up |
| Muted | 0.45–0.75 | 0.03–0.08 |
| Light | 0.85–0.97 | 0–0.12 |
| Dark | 0.20–0.40 | 0–0.15 |
| Tinted greys | 0.15–0.95 | 0.005–0.025 |
| Greys | R = G = B, any of the 256 levels from #000000 to #FFFFFF | |
| Hue family | OKLCH hue |
|---|---|
| Red | 10° to under 45° |
| Orange | 45° to under 85° |
| Yellow | 85° to under 120° |
| Green | 120° to under 175° |
| Cyan / teal | 175° to under 230° |
| Blue | 230° to under 285° |
| Purple | 285° to under 335° |
| Pink | 335° to under 10° |
With Any color and a hue family, the tool keeps drawing fair 24-bit colors until one has that hue and a chroma of at least 0.02.
Harmony palettes rotate the hue of the base color in HSL and keep its saturation and lightness, so you can check them in any color picker. Even lightness rotates in OKLCH instead, keeping L and C (C is lowered only when sRGB cannot show it). The monochromatic ladder uses HSL lightness 15, 30, 45, 65 and 85 %, with the step closest to the base replaced by the base itself.
Contrast is the WCAG 2.2 ratio against black and white text: 4.5:1 for normal text (AA), 3:1 for large text, 7:1 for AAA. A ratio just under a limit is never rounded up to pass.
Names are the nearest CSS named color by ΔEOK (distance in OKLab): “≈” within 0.05, “near” beyond that. Distinct sets keep every pair at least the chosen ΔEOK apart; if that is impossible for the count, the bar is lowered in 0.01 steps and the tool tells you.
Everything runs in your browser. Nothing is uploaded; history stays in this browser only.
Space new colors · L lock the focused color · C copy all HEX
Four ways to roll, in twenty seconds
A random color generator only earns its place if the color it hands you is ready to use, so every roll here arrives with HEX, RGB, HSL and OKLCH codes, the nearest color name and a text-contrast score. Pick the mode that fits the job:
- Any color. A fair pick from all 16,777,216 sRGB colors. Black, white, greys and the muddy in-betweens are all in the pool, which is exactly what you want for test data and honest creative prompts.
- Style. Random within a range: pastel, vivid, neon, muted, light, dark, greys or tinted greys, optionally narrowed to a hue family such as blue or orange.
- Palette. A random base color plus a harmony rule: complementary, analogous, triadic, split-complementary, tetradic or a monochromatic ladder of tints and shades.
- Distinct. A set in which every color keeps a minimum distance from all the others, for chart series, map categories and labels.
Then work the way I do: press Space to reroll, lock the swatch you like with its padlock (or the L key), reroll the rest until the set clicks, and copy. C copies every HEX code at once, and the share link stores the whole set in the URL, so a teammate opens exactly the colors you see.
What a fair random color generator actually does
Plenty of random color tools quietly draw from a narrow band, and the old version of this one did too. It picked whole-number HSL values with saturation 15–100 % and lightness 20–85 %. That reaches only 1,743,568 of the 16,777,216 possible colors, about 10.4 %, and pure black, pure white, mid grey #808080 and near-whites like #F0F8FF could never come up. The classic JavaScript one-liner has its own blind spots: multiplying by 16777215 never returns white, and forgetting to pad the hex gives broken codes like #123b (the usual snippet shows both).
Any color mode takes one 24-bit number from the browser's cryptographic random source, crypto.getRandomValues, and writes it as six hex digits with leading zeros kept. Every color has the same 1-in-16,777,216 chance. The side effect surprises people: a fair pick is mostly mid-tone and fairly saturated, and pastels are rare. In my own sample of 200,000 uniform colors, fewer than 3 in 100 fell in the usual pastel band (HSL saturation 15–50 %, lightness 70–95 %), so ten fair rolls usually give you no pastel at all. That is what the Style modes are for.
Styled modes are random too, but inside a published range. I define them in OKLCH, where L follows perceived lightness and C follows colorfulness, because HSL lightness misleads: yellow and cyan at 50 % HSL lightness look far brighter than blue at the same number (Björn Ottosson's OKLab write-up shows why). A draw that falls outside the sRGB gamut is thrown away and drawn again, so you never get a clipped, flattened color.
| Style | Lightness L | Chroma C | Typical use |
|---|---|---|---|
| Pastel | 0.84–0.94 | 0.03–0.08 | soft backgrounds, baby and spring themes |
| Vivid | 0.55–0.75 | 0.15–0.30 | accents, buttons, illustration |
| Neon | 0.70–0.90 | 0.20 and up | posters, game UI, highlights |
| Muted | 0.45–0.75 | 0.03–0.08 | dusty, earthy, editorial palettes |
| Light | 0.85–0.97 | up to 0.12 | page and card backgrounds |
| Dark | 0.20–0.40 | up to 0.15 | dark themes, text colors |
| Tinted greys | 0.15–0.95 | 0.005–0.025 | UI neutrals with a hint of hue |
| Greys | R = G = B | none | any of 256 neutral levels, black to white |
Hue families use half-open ranges on the OKLCH hue circle, so no hue belongs to two families, and red is no longer drawn twice as often at 0°, a bias the old version had.
Reading the codes on a swatch
Take #3B82F6, a typical interface blue. Here is the same color in the four notations the tool prints:
| Format | Value | When I reach for it |
|---|---|---|
| HEX | #3B82F6 | pasting into CSS, Figma or a brand sheet |
| RGB | rgb(59, 130, 246) | channels 0–255: hex 3B = 59, 82 = 130, F6 = 246 |
| HSL | hsl(217, 91%, 60%) | quick hand tweaks of hue, saturation, lightness |
| OKLCH | oklch(62.31% 0.188 259.8) | building palettes with even perceived lightness |
All four are derived from the hex, so the HSL you see after restoring a set from history matches the HSL you saw when it was generated. The name on each card carries "≈" because it is the nearest CSS named color by ΔEOK, the straight-line distance in OKLab. Measured in plain RGB, a dark brown like #5A3C28 comes out as "Dark Olive Green"; measured perceptually, the match makes sense. When even the nearest name is far off, the card says "near …" instead of pretending.
From one lucky roll to a palette
Ten unrelated random colors almost always clash. What works is one random decision, the base, and a rule for the rest. Say the roll gives teal #0E7C86, which is hsl(185, 81 %, 29 %). Rotating the hue while keeping saturation and lightness gives these harmonies:
| Rule | Hue offset | Colors |
|---|---|---|
| Complementary | +180° | #86180E |
| Analogous | −30°, +30° | #0E8654, #0E4086 |
| Triadic | +120°, +240° | #860E7C, #7C860E |
| Split-complementary | +150°, +210° | #860E40, #86540E |
| Tetradic (square) | +90°, +180°, +270° | #540E86, #86180E, #40860E |
| Monochromatic | lightness 15 / 29 / 45 / 65 / 85 % | #074045, #0E7C86, #16C0D0, #5DE2EE, #BAF3F8 |
Now the catch most generators never mention. The three triad colors share the same HSL lightness, 29 %, yet white text scores 4.95:1 on the teal, 8.87:1 on the magenta and only 3.98:1 on the olive. One looks heavy, one looks washed out. The even-lightness option rotates the hue in OKLCH at fixed L and C instead, so the set really sits at one visual weight. My habit: lock the base, try both versions and keep whichever suits the layout, then give one color most of the space and save the loudest for small accents. The full method is in Random color palettes that work.
Will text read on it?
Every swatch shows whether black or white text reads better on it, with the ratio and a badge. The thresholds come from WCAG success criterion 1.4.3: at level AA, 4.5:1 for normal text and 3:1 for large text (about 24 px, or 18.5 px bold); at AAA, 7:1 and 4.5:1. Don't trust your eye near the line. #777777 on white is 4.48:1 and fails AA for body text, while #767676, one step darker, passes at 4.54:1. The tool compares the unrounded ratio, so a 4.499 never slips through as "4.50".
| Swatch | White text | Black text | Verdict |
|---|---|---|---|
#0E7C86 | 4.95:1 | 4.25:1 | white, AA |
#3B82F6 | 3.68:1 (large text only) | 5.71:1 | black, AA |
#F5B700 | 1.80:1 | 11.66:1 | black, AAA |
Here is a fact I lean on all the time: no color makes both black and white fail 4.5:1. The two ratios meet at a relative luminance of about 0.179, at roughly 4.58:1, and the hardest real grey, #757575, still gives 4.61:1 with white. So every random color can carry readable text; the only question is which one. In my uniform sample, black text passed AA on about 65 % of colors and white on about 36 %, which is why black wins more often than designers expect.
Colors people can tell apart
For a chart, "random" is not enough: two series must never look alike. Fully random sets regularly include near-twins. #FF0000 and #FF4500 are only 0.050 apart in ΔEOK; #000080 and #191970, 0.054. Distinct mode keeps every new color at least a chosen distance from all the others (0.12 by default, adjustable from 0.05 to 0.25) and reports the closest pair in the current set. For reference, the familiar six-color set #E6194B #3CB44B #FFE119 #4363D8 #F58231 #911EB4 has its closest pair at 0.175, the blue and the purple. The 0.12 is my working threshold, not a standard. More in Random colors you can tell apart.
Taking the colors with you
- HEX list for a brief or a chat message.
- CSS custom properties such as
--color-1: #0E7C86;, ready for a stylesheet. - Tailwind
colorssnippet for the config file. - JSON with hex, rgb, hsl, oklch and name for each color, for design tokens and scripts.
- SVG strip and PNG for mood boards and slides.
- Gradient: a CSS
linear-gradient()of the current set in one click. - Share link like
/#c=0E7C86-860E7C-7C860Ethat rebuilds the set without any server.
Everything runs in your browser. No color, history or export is sent anywhere; history lives in your browser's local storage and you can clear it at any time. For soft palettes, read Random pastel colors; to generate colors in your own code, see Random color in code.
The color math behind every swatch
Every number on a card can be checked by hand. These are the rules the tool follows:
- Randomness:
crypto.getRandomValuesonly. Any color is a 32-bit value shifted right by 8 bits (u32 >>> 8), which gives every 24-bit number equal odds with no modulo bias; ranges use rejection sampling. - HSL and RGB: the CSS Color 4 conversion, channels rounded to whole numbers.
- OKLab and OKLCH: Ottosson's published matrices; ΔEOK is the Euclidean distance in OKLab.
- Harmonies: hue rotation as listed above, the same offsets the common harmony definitions use.
- Contrast: the WCAG formula below on linearised sRGB (c ≤ 0.04045 → c / 12.92, otherwise ((c + 0.055) / 1.055) to the power 2.4).
ratio = (L lighter + 0.05) / (L darker + 0.05)
| Input | Expected result |
|---|---|
contrast #FFFFFF vs #000000 | 21.00:1 |
#777777 and #767676 on white | 4.48:1 (fails AA) and 4.54:1 (passes AA) |
#3B82F6 | rgb(59, 130, 246) · hsl(217, 91%, 60%) · oklch(62.31% 0.188 259.8) · white 3.68, black 5.71 → black text |
triadic of #FF0000 | #00FF00, #0000FF |
| 24-bit values 0, 0x00123B, 16777215 | #000000, #00123B, #FFFFFF |
The tool's test page runs these cases, so a change that breaks the math shows up before it reaches you.
Common questions
How many colors can a random color generator pick from?
In sRGB hex there are 256 × 256 × 256 = 16,777,216 colors. Any color mode gives each of them the same chance, including pure black, pure white and every grey.
How do I get a random hex color in JavaScript?
One line does it: '#' + (crypto.getRandomValues(new Uint32Array(1))[0] >>> 8).toString(16).padStart(6, '0'). The code guide on this site covers Python and CSS too, and the bugs in the common Math.random snippet.
What makes a color pastel?
There is no official definition. Pastels are light and low in colorfulness; a rough HSL band is saturation 15–50 % and lightness 70–95 %, and the Pastel style here uses OKLCH lightness 0.84–0.94 with chroma 0.03–0.08.
Can I get the same color twice?
Yes, every roll is independent. Among ten fair colors the chance of a repeat is about 3 in a million; among 1,000 it is about 2.9 %. Near-twins are far more common, which is what Distinct mode prevents.
Why does my random palette clash?
Independent random picks ignore how hues relate and how light each color is. Use Palette mode, lock a base you like, and let a harmony rule and a lightness plan choose the rest.
Is it free, and does anything get uploaded?
It is free with no sign-up. Colors are generated in your browser and nothing is uploaded; history stays in your browser's local storage.
Guides
- Random color palettes that work: complementary, analogous, triadicSix hue rules worked through on one teal base, why equal HSL lightness still looks uneven, and a lock-and-reroll routine.Reading time: 6 min
- Random pastel colors: the HSL and OKLCH ranges behind themPastel has no official definition. Compare the HSL rule and the OKLCH band, with real hex codes, contrast numbers and a six-color pastel set.Reading time: 6 min
- Distinct random colors for charts, maps and labelsWhy eight random colors usually include a near-twin, how to measure the gap with ΔEOK, and how many colors really fit.Reading time: 6 min
- Random color in code: JavaScript, CSS and Python done rightFix the one-liner that returns invalid hex in 1 run of 16, then get crypto-grade, seeded, CSS and Python versions that cover every color.Reading time: 6 min