Random Color Generator

Colors picked at random, but limited to a mood (pastel, vivid, earthy, dark) so you don’t get a screen full of mud. Click any swatch to copy its code; space bar for a fresh batch.

Press Space to generate again. Click a swatch to copy it.

Why Random Colors Usually Look Bad (and How to Generate Good Ones)

Ask a computer for a random color and you will usually get something like #7A6B52: a vaguely brownish, greyish, forgettable color. Do it twenty times and most results look similar. This surprises people, because there are over 16 million possible colors. The reason lies in how the RGB color space is shaped, and fixing it is surprisingly simple.

Muddy random RGB colors compared with constrained pastel colors from HSL

The problem with picking three random numbers

The simplest random color generator picks a random value from 0 to 255 for red, green and blue. Every color in the RGB cube is equally likely. The trouble is that most of the cube is not where vivid, attractive colors live.

Saturated colors need one channel high and at least one channel low. Pure red is (255, 0, 0). But if each channel is random, it is much more likely that all three land somewhere in the middle, and when R, G and B are close to each other, the result is greyish. Pastels need all three channels high, which is also uncommon. So uniform randomness produces lots of medium-dark, low-saturation colors: browns, olives, slate blues and muddy purples.

MethodTypical resultsUsefulness
Random R, G, B (0–255 each)Many muddy mid-tonesLow for design, fine for test data
Random hue, fixed saturation and lightnessEven rainbow at one “mood”High
Random hue with S and L limited to a rangeVaried but coherent setsHigh
Random hue using the golden angleEvenly spread, distinct colorsGreat for charts and avatars
Random within a perceptual space (OKLCH)Even perceived brightnessHighest consistency

Constraining randomness with HSL

The fix is to randomize in HSL (hue, saturation, lightness) instead of RGB, and to only randomize what you want to vary. If you pick a random hue from 0 to 360° but keep saturation between 45% and 80% and lightness between 78% and 90%, every result is a pastel. Keep saturation high and lightness around 50%, and every result is vivid.

That is how the “mood” options in the random color generator above work:

  • Pastel: medium saturation, high lightness.
  • Vivid: high saturation, mid lightness.
  • Dark: moderate saturation, low lightness.
  • Light: low to medium saturation, very high lightness.
  • Earthy: hues limited to the orange-to-olive range with low saturation.
  • Neutral: almost no saturation, so you get tinted greys.

Each mood is just a box inside HSL space. Random values inside a well-chosen box always look like they belong together.

The golden angle trick

If you need a set of colors that are all clearly different, for example for chart series or user avatars, randomness can produce two similar hues next to each other. A neat alternative is the golden angle: about 137.5°. Start at any hue and add 137.5° for each new color (wrapping around at 360°). Because 137.5° is related to the golden ratio, the hues never repeat and stay well spread out, no matter how many colors you generate. The same principle explains the spiral pattern of seeds in a sunflower.

Perceptual brightness: why yellow looks lighter than blue

Even with HSL constraints, a set of “vivid” colors at 50% lightness won’t look equally bright. Yellow and cyan appear much lighter than blue and purple at the same HSL lightness. If you need colors of truly equal visual weight, for instance for a set of category tags, generate them in a perceptual color space like OKLCH, where the lightness value matches how bright colors actually look. Modern CSS supports oklch() directly in all major browsers.

What random colors are good for

Breaking creative block. Sometimes you don’t know what you want until you see it. Generate a dozen colors, notice which ones you react to, and use that as a starting point for a proper palette with the color palette generator.

Placeholder content. Random backgrounds for avatar initials, cards in a prototype or tiles in a mockup make interfaces look more realistic than a wall of identical grey boxes.

Test data. When building charts, random colors help you see whether a layout breaks with many series. (For final charts, use a deliberate palette.)

Generative art. Random colors with constraints are the foundation of most generative and algorithmic art. Constraining hue to a narrow band while varying lightness creates natural, painterly variation.

Games and fun. Daily color challenges, guessing games and color-matching exercises all rely on random colors.

What random colors are not good for

Brand identity, accessibility-critical text, and data where colors carry meaning should never be random. A brand needs colors chosen for meaning and recognition. Text needs guaranteed contrast. Data colors need to be distinguishable and, ideally, color-blind safe; see our guide to designing for color blindness.

Using a random color responsibly

Once a random color catches your eye:

  1. Copy the HEX code.
  2. Generate a harmony around it with the palette generator.
  3. Create lighter and darker variants with a tints and shades generator.
  4. Check text contrast with the contrast checker.
  5. Name it, using the color name finder if you want a descriptive label.

A small coding note

If you generate random colors in your own code, avoid this common bug: Math.floor(Math.random() * 16777215).toString(16) can return fewer than six hex digits (for example fa3 when the number is small). Always pad the result: .padStart(6, '0'). And note that multiplying by 16,777,215 instead of 16,777,216 means pure white can never be generated.