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.
| Mode | OKLCH lightness | OKLCH chroma | First 4 colors for seed 42 |
|---|---|---|---|
| Balanced | 50–80% | 0.1–0.2 | #5E8800 #B96F26 #AEA500 #009D9B |
| Pastel | 85–93% | 0.04–0.09 | #C7DDAD #F2D0B5 #E6E3A8 #99EAE8 |
| Vivid | 55–80% | 0.18–0.32 | #679400 #CD7200 #B3AA00 #00A7A5 |
| Dark | 25–45% | 0.05–0.15 | #223400 #4F2800 #4B4600 #00403F |
| Muted | 45–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:
| # | HEX | RGB | OKLCH L | OKLCH C | Nearest CSS name |
|---|---|---|---|---|---|
| 1 | #E5D9EE | rgb(229, 217, 238) | 90.1% | 0.031 | gainsboro |
| 2 | #D38B39 | rgb(211, 139, 57) | 69.6% | 0.130 | peru |
| 3 | #53491C | rgb(83, 73, 28) | 40.5% | 0.065 | darkslategray |
| 4 | #85C137 | rgb(133, 193, 55) | 74.4% | 0.177 | yellowgreen |
| 5 | #BEC049 | rgb(190, 192, 73) | 78.4% | 0.140 | darkkhaki |
| 6 | #133AED | rgb(19, 58, 237) | 47.6% | 0.264 | blue |
With Pastel and the same seed, every color is light and soft, with OKLCH lightness from 85.2% to 92.1%:
| # | HEX | RGB | OKLCH L | OKLCH C | Nearest CSS name |
|---|---|---|---|---|---|
| 1 | #C7DDAD | rgb(199, 221, 173) | 86.9% | 0.068 | palegoldenrod |
| 2 | #F2D0B5 | rgb(242, 208, 181) | 87.9% | 0.053 | peachpuff |
| 3 | #E6E3A8 | rgb(230, 227, 168) | 90.4% | 0.076 | palegoldenrod |
| 4 | #99EAE8 | rgb(153, 234, 232) | 88.5% | 0.079 | paleturquoise |
| 5 | #FFDBD9 | rgb(255, 219, 217) | 92.1% | 0.040 | mistyrose |
| 6 | #B0D8D4 | rgb(176, 216, 212) | 85.2% | 0.042 | lightblue |
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
- Multiplying by 16777215 instead of 16777216.
Math.floor(Math.random() * 16777215)can never return 16,777,215, so#FFFFFFnever comes up. - Leaving out the padding. Without
padStart, a low number gives a string of 1 to 5 digits (255 gives#ff). Three and four digits are valid CSS shorthand for a different color (#fffis white, not#000fff); 1, 2 and 5 digits are invalid. - Using
Math.random().toString(16).slice(2, 8). The hex string of a random fraction can have fewer than 6 digits after the point (0.5 is0.8in hex), which gives a short, broken code. - Expecting random colors to match. Uniform random colors vary in lightness and chroma; use a range mode, or the color palette generator for color harmonies, when the colors need to work together.
- Using text on a random background without checking. Run the pair through the contrast checker; the WCAG 2.2 AA minimum for normal text is 4.5:1 (3:1 for large text).