Random color generator

Click Generate (or press Space) for up to 24 random colors with their HEX, RGB, HSL and OKLCH codes. Use Any color for a fair pick from all 16,777,216 HEX values, or a range such as pastel or vivid for colors that work well together.

Custom OKLCH ranges
Custom OKLCH hue range clockwise; 300 to 60 wraps through 0°

Press Space to generate when focus is not in a text field or on a button. Locked colors stay when you generate again. The page address holds the seed and settings, not the colors, so a shared link rebuilds the unlocked colors.

Copy all

Open in palette generator

How to use the random color generator

  1. Set how many Colors you want, from 1 to 24.
  2. Choose the Colors to pick from: Any color for all 16,777,216 HEX values, a range such as Pastel, Vivid, Dark or Muted, or Custom ranges to set OKLCH lightness and chroma yourself.
  3. Optionally pick a Hue, such as Blues or Pinks, or a custom hue range in degrees.
  4. Click Generate or press Space for a new set. Click Lock on a color to keep it (the button changes to Locked).
  5. Copy a single HEX, RGB, HSL or OKLCH value, or use Copy all as a HEX list, CSS variables or JSON. Open the set in the palette generator, or a single color in the color picker.
  6. Share the page address: it holds the seed and settings, so anyone who opens it gets the same unlocked colors.

What this random color generator does

It picks colors at random and shows each one as a swatch with its HEX, RGB, HSL and OKLCH codes and the nearest CSS color name. If a color exactly matches a named color with its own page, it links there. You can generate up to 24 at once, lock the ones you like, and copy the whole set. Colors are generated in your browser; nothing is sent anywhere.

How it picks colors

With Any color and all hues, every one of the 16,777,216 six-digit HEX values (256 × 256 × 256) is equally likely. A new seed is 32 random bits from your browser's crypto.getRandomValues(). For each color slot the tool scrambles the seed with a reversible hash and uses 24 of the bits as the red, green and blue bytes, a whole number from 0 to 16,777,215. Because the hash is reversible, no value is favored. With a hue filter, it draws again (rejection sampling) until the color's OKLCH hue falls in the range and its chroma is at least 0.03 (so grays are skipped); the extra draws come from a seeded generator, so the colors that pass are close to equally likely.

The other modes pick in OKLCH instead: a lightness, a chroma and a hue, each uniformly within its range. Many of those combinations are outside what an sRGB screen can show (it has no light, intense blue, for example), so the tool lowers the chroma, keeping lightness and hue, until the color fits, then rounds it to 8-bit RGB. These modes are not uniform over HEX values: colors near the edge of the screen's range come up more often, because every out-of-range pick lands there.

With the same seed, the modes share hues and differ in lightness and chroma.

ModeOKLCH lightnessOKLCH chromaFirst 4 colors for seed 42
Balanced50–80%0.1–0.2#5E8800 #B96F26 #AEA500 #009D9B
Pastel85–93%0.04–0.09#C7DDAD #F2D0B5 #E6E3A8 #99EAE8
Vivid55–80%0.18–0.32#679400 #CD7200 #B3AA00 #00A7A5
Dark25–45%0.05–0.15#223400 #4F2800 #4B4600 #00403F
Muted45–75%0.02–0.07#627051 #847061 #95946B #4D8684

The hue filters are OKLCH hue ranges: Reds 10–40°, Oranges 40–75°, Yellows 75–115°, Greens 115–165°, Teals and cyans 165–220°, Blues 220–280°, Purples 280–335° and Pinks 335–10°. A dark orange looks brown and a light red looks pink, so the names are a guide rather than exact.

Random colors vs a random color palette

Picking each RGB channel at random is fair to every HEX code, but most codes are not vivid. A strong color needs a big gap between its largest and smallest channel (pure red #FF0000 has the full 255), while three random numbers usually land closer together, which mixes in gray. HSL and HSV call that gap chroma. Counting all 16,777,216 colors, about half (49.7%) have a gap below 128, and only about 1 in 8 (12.5%) reach 200 or more.

Random channels also give random lightness, so one set can mix very dark and very light colors. In the worked example below, OKLCH lightness runs from 40.5% to 90.1%. The OKLCH modes fix lightness and chroma to a band, which is why their colors tend to look like they belong together. Neither approach is better in general: uniform colors are the fair choice for test data and placeholder colors, while ranges suit palettes and charts.

Worked example: seed 42

With seed 42, 6 colors, all hues and Any color, the tool gives:

#HEXRGBOKLCH LOKLCH CNearest CSS name
1#E5D9EErgb(229, 217, 238)90.1%0.031gainsboro
2#D38B39rgb(211, 139, 57)69.6%0.130peru
3#53491Crgb(83, 73, 28)40.5%0.065darkslategray
4#85C137rgb(133, 193, 55)74.4%0.177yellowgreen
5#BEC049rgb(190, 192, 73)78.4%0.140darkkhaki
6#133AEDrgb(19, 58, 237)47.6%0.264blue

With Pastel and the same seed, every color is light and soft, with OKLCH lightness from 85.2% to 92.1%:

#HEXRGBOKLCH LOKLCH CNearest CSS name
1#C7DDADrgb(199, 221, 173)86.9%0.068palegoldenrod
2#F2D0B5rgb(242, 208, 181)87.9%0.053peachpuff
3#E6E3A8rgb(230, 227, 168)90.4%0.076palegoldenrod
4#99EAE8rgb(153, 234, 232)88.5%0.079paleturquoise
5#FFDBD9rgb(255, 219, 217)92.1%0.040mistyrose
6#B0D8D4rgb(176, 216, 212)85.2%0.042lightblue

Each color slot has its own random stream derived from the seed, so changing the count from 6 to 8 keeps the first 6 colors and adds 2, and locking a color leaves the others unchanged. The seed is a whole number from 0 to 4,294,967,295; any other text you type, such as a word, is hashed into one. The range modes and hue filters draw their numbers from mulberry32, a small seeded generator that is fast and repeatable but not meant for security.

How to generate a random hex color in JavaScript

const n = Math.floor(Math.random() * 0x1000000); // 0 to 16777215
const color = "#" + n.toString(16).padStart(6, "0");

0x1000000 is 16,777,216, so n covers every color from #000000 to #FFFFFF. padStart(6, "0") adds the leading zeros that small numbers need: without it, 255 becomes #ff instead of #0000ff. For a random CSS color in OKLCH, a string like `oklch(70% 0.12 ${Math.random() * 360})` keeps lightness and chroma fixed, but some hues at that chroma are outside sRGB and the browser has to map them into range.

Common mistakes

Key terms

Hex color
A color written as a # followed by hexadecimal digits for red, green and blue, such as #4F46E5. Each pair runs from 00 to FF (0 to 255). An optional fourth pair sets opacity, and 3- or 4-digit shorthand doubles each digit.
OKLCH
A CSS color format of lightness, chroma and hue, built on the OKLab color space published by Björn Ottosson in 2020. Equal steps in its lightness look roughly equal to the eye, which plain HSL does not manage. Tailwind CSS v4 defines its default palette in OKLCH.
Chroma
How colorful a color is compared with a gray of the same lightness. In OKLCH, 0 is a neutral gray and higher numbers are more saturated. The highest chroma a screen can show depends on the hue, the lightness and the gamut of the display.
Uniform distribution
A random pick where every possible outcome is equally likely. For six-digit HEX colors that means each of the 16,777,216 values has a 1 in 16,777,216 chance.
Random seed
The starting value of a pseudorandom number generator. The same seed always produces the same sequence, which makes a random result repeatable and shareable.
Pseudorandom number generator
An algorithm that produces numbers that look random from a starting seed. Small generators such as mulberry32 are fast and repeatable but predictable, so security code uses a cryptographic source such as crypto.getRandomValues() instead.
Rejection sampling
Drawing random values and throwing away the ones that do not meet a condition until one does. The values that are kept stay uniformly distributed over the ones that meet it.

Frequently asked questions

How many random colors are there?
16,777,216 six-digit HEX colors: 256 values for each of red, green and blue. In Any color mode each one is equally likely.
How do I get the same random colors again?
Keep the seed and settings: they are saved in the page address, so reloading or sharing the link gives the same colors. Locked colors are not in the link.
What is the difference between Any color and the other modes?
Any color is a uniform pick over all HEX values. The other modes pick OKLCH lightness, chroma and hue within ranges, so their colors have a similar lightness and intensity.
Can I get a random color in one hue, such as blue?
Choose Blues (or another family) under Hue. With seed 42 and Any color, the first three blues are #330FE4, #4329F5, #707BEA.
Are the colors truly random?
New seeds come from your browser's crypto.getRandomValues(). In Any color mode each color is a fixed hash of the seed; the range modes and hue filters use mulberry32, a repeatable pseudorandom generator. Both are fine for colors but not for anything secret.
How do I make a random color palette?
Pick a range mode such as Balanced or Pastel and generate until you like the set, then open it in the palette generator to adjust it or export Tailwind and SCSS code. The palette generator takes up to 10 colors.
Why does a random color have no exact CSS name?
Only 139 distinct colors have CSS names, so the tool shows the closest one by OKLab distance and marks it exact only when the codes match. See HTML color names.

Sources: CSS Color 4: HEX notation, CSS Color 4: named colors, CSS Color 4: OKLab and OKLCH, A perceptual color space for image processing (Björn Ottosson), MDN: Math.random(), MDN: Crypto.getRandomValues(), MDN: String.prototype.padStart(). Last checked 2026-11-17.