Skip to content

Random Color Generator

Updated:

Roll a batch of 1–50 random colors as HEX, RGB and HSL. Pick a mode such as pastel, neon or grayscale, apply a palette harmony, lock your favorites, and copy or export everything with one click.

Roll a Fresh Batch of Random Colors

Input Fields
N
1–50 swatches per batch.
Every change redraws the unlocked swatches. The Space bar anywhere on this page bumps this counter for you.
If enabled, the result will update automatically when you change any value.

Random Color Formula

Formula
\[ H \sim \mathcal{U}(h_1, h_2), \quad S \sim \mathcal{U}(s_{\min}, s_{\max}), \quad L \sim \mathcal{U}(l_{\min}, l_{\max}) \\ C = (1 - |2L - 1|)\,S, \quad H' = \tfrac{H}{60}, \quad X = C\,(1 - |H' \bmod 2 - 1|), \quad m = L - \tfrac{C}{2} \]

Where:

  • \(H\) — hue in degrees (0–360), drawn uniformly from the mode's hue window
  • \(S\) — saturation in percent, drawn from the mode's saturation window
  • \(L\) — lightness in percent, drawn from the mode's lightness window
  • \(C\) — chroma, \(X\) — intermediate channel value, \(m\) — lightness offset added to each RGB channel

Each swatch starts as three independent uniform random draws in the HSL color model. The second line then converts the chosen \(H, S, L\) into RGB: the sector of the color wheel (given by \(H'\)) decides which of \(C\), \(X\) or 0 goes into red, green and blue before \(m\) is added. Finally, the WCAG relative luminance \(L_{\mathrm{rel}} = 0.2126R' + 0.7152G' + 0.0722B'\) and the contrast ratio \(\mathrm{CR} = \frac{L_1 + 0.05}{L_2 + 0.05}\) decide whether black or white text is more readable on the swatch.

Random Color – Calculation Example

Example: the generator draws hue \(210^\circ\), saturation 80% and lightness 60% — three values that all fall inside the default "any color" window.

\[ C = (1 - |2 \cdot 0.60 - 1|) \cdot 0.80 = 0.64, \quad H' = \tfrac{210}{60} = 3.5, \quad X = 0.64\,(1 - |1.5 - 1|) = 0.32, \quad m = 0.60 - 0.32 = 0.28 \]

Since \(3 \le H' < 4\), the blue channel gets \(C\), green gets \(X\), and red gets 0:

\[ (R, G, B) = (m,\; m + X,\; m + C) \cdot 255 = (0.28,\; 0.60,\; 0.92) \cdot 255 \approx (71,\; 153,\; 235) \]

Result: rgb(71, 153, 235), which converts to the hex code #4799EB — the string you can copy from the swatch.

How to use the calculator

  1. Enter how many swatches you want in Colors to generate (N) — anything from 1 to 50.
  2. Choose a Mode: Any color, Pastel, Dark, Vivid / neon, Grayscale, Warm hues, Cool hues, or Within a hue range. Each mode is a window on the HSL scale (for example, pastel limits saturation to 30–62% and lightness to 74–90%).
  3. If you picked Within a hue range, set Hue range — from (°) and Hue range — to (°). If the start exceeds the end, the range wraps through red, so 330° to 30° covers reds and magentas on both sides.
  4. Optionally pick a Palette harmony: analogous (±30° around one base hue), complementary (180° flip), triadic (120° steps) or monochrome. With None, every swatch is fully independent.
  5. Set what a click on the big swatch copies under Swatch click copies — HEX, RGB or HSL. The small values below each swatch are always individually clickable.
  6. Press Space anywhere outside a form field (or increase the Shuffle counter) to redraw. Click 🔒 on a swatch you like first, and shuffling leaves it untouched.
  7. Copy single values from the palette, or use the export buttons for CSS variables, JSON, or a downloadable PNG strip. The history panel keeps your last 20 colors.

What is a random color?

A "random color" is a color whose parameters are drawn by chance rather than picked by hand. This generator works in the HSL model: hue (position on the color wheel, 0–360°), saturation (intensity, 0–100%) and lightness (brightness, 0–100%). Drawing all three at once produces any color the screen can show; restricting the draw to a window — high lightness and low saturation for pastels, high saturation and mid lightness for neon — produces a batch with a consistent mood.

Because each swatch is stored as HSL, RGB and HEX at the same time, you can take the result straight into CSS, design tools or a color converter such as our Color Converter when you need a different notation.

The randomness itself comes from crypto.getRandomValues(), the cryptographic random number generator built into your browser. There is no seed and no pattern, so two batches generated with the same settings will look completely different — the same principle behind our Password Generator and UUID Generator. A Math.random fallback only fires on very old browsers.

The harmony options answer a common design problem: fully random colors rarely look good together. They solve it by drawing one extra random base hue and then placing the swatches at fixed angular offsets from it, which is why analogous, complementary and triadic batches feel coordinated even though every batch is new.

Interpreting the contrast ratios

Every swatch shows a WCAG 2.x contrast check: one ratio for black text and one for white text on that color. Ratios of 4.5:1 or higher meet the AA level for normal text, and 7:1 or higher meet AAA. The swatch labels itself with the better color. Treat this as a quick accessibility screen — if you plan real text on one of these colors, aim for the AA threshold for body text and 3:1 for large text.

Limitations and practical tips

  • Modes and harmonies combine freely, but Grayscale holds saturation at 0%, so the hue rotations of a harmony have no visible effect — switch the harmony off for pure random grays.
  • HSL windows are simple and fast, not perceptually uniform. Two swatches of equal lightness can look differently bright (yellow vs. blue), so judge the final palette with your eyes, not the numbers alone.
  • Locked swatches survive shuffles, mode changes and count changes, but a page reload resets everything — including the history panel, which lives only in this browser tab and is never stored or uploaded.
  • Exports match the palette exactly as displayed, locked swatches included: the CSS block defines one custom property per color, the JSON carries HEX, RGB and HSL arrays per color, and the PNG is drawn locally on a canvas.
  • If the Space bar does nothing in your setup, click the Shuffle number field and type a larger value — it redraws the same way.
  • For random output in other forms — letters, orderings, text — see our Random Letter Generator and List Randomizer.

Frequently Asked Questions

How do I generate a random color by hand?

Pick six random digits from 0–9 and A–F and prefix a #: each pair is one channel, for example #7C2FA1. Each channel is a uniform draw from 0–255, unlike this generator, which draws in HSL so the results cover the whole wheel evenly. For a quick offline trick, roll three dice or a random number table for the red, green and blue values and convert each to two hexadecimal digits.

Why does this generator pick colors in HSL instead of pure random RGB?

Fully random RGB channels are mathematically uniform but visually biased — many results land in muddy mid-grays or near-blacks, and the wheel's edges are underrepresented. Drawing hue, saturation and lightness separately lets the generator trim ugly extremes, keep every swatch visible, and offer modes like pastel or neon by simply narrowing the saturation and lightness windows while hue stays random.

How do I convert between HEX, RGB and HSL myself?

HEX to RGB: split the six digits into three pairs and convert each from hexadecimal, so #4799EB is (71, 153, 235). RGB to HSL: scale the channels to 0–1, then lightness \(L = \tfrac{\max+\min}{2}\), saturation depends on that lightness, and hue follows which channel is largest. The reverse conversion is shown in full in the formula section above. Our Color Converter page does all three notations instantly.

What contrast ratio do I need for readable text on a random color?

WCAG 2.x requires at least 4.5:1 for normal body text (AA level) and 3:1 for large text of 24 px or more; 7:1 is the stricter AAA level. Every swatch here prints both ratios for you, but they are a quick screen, not a full audit — check your final design with a dedicated contrast checker, including hover and disabled states.

How can I get only pastel, neon or dark random colors?

Switch the Mode dropdown: pastel keeps saturation at 30–62% and lightness at 74–90%, vivid/neon locks saturation to 85–100% around a mid lightness, and dark limits lightness to 10–30%. If you need a narrower slice, use "Within a hue range" — for example 0° to 70° for golds and oranges — and combine it with any mode except gray.

Are the colors truly random, and can I reproduce a batch later?

Yes and no. The draws use crypto.getRandomValues(), the browser's cryptographic generator, so the output is unpredictable and unbiased. There is no seed, however, so you cannot reproduce an earlier batch — if you see colors you want to keep, lock the swatches before shuffling and export them as CSS variables, JSON or a PNG while they are still on screen.

Why do two colors with the same lightness percentage look differently bright?

HSL is simple but not perceptually uniform — the human eye reads a yellow at 60% lightness as far brighter than a blue at 60%. That is a known limitation of HSL-based generation, not a bug in the draw. Judge final palettes with your eyes, and if perceptual evenness matters, convert candidates to a perceptual space such as OKLCH before committing.

Leave a Reply

Your email address will not be published. Required fields are marked *