Random Hex Generator
Generates 1 to 10 random hex strings of 1 to 20 digits with a # prefix. Use length 6 for random color codes or any length for hex IDs and test data.The Random Hex Generator produces random hexadecimal strings. You choose how many (1 to 10) and how long (1 to 20 digits), press the button, and each result appears on a card with a copy button. Every string starts with a # and uses the digits 0–9 and A–F, so a six-digit result is a valid CSS color code and any other length is a random hex value you can use as an ID, a test fixture or a seed.
Settings
- Number of hexes: 1 to 10 per press. Default is 1.
- Length of hex: 1 to 20 hex digits, not counting the #. Default is 6, which is the length of a standard web color.
Each digit is picked independently and uniformly from the sixteen hex characters, so every string of a given length is equally likely. The tool does not check for duplicates across a batch; at six digits there are 16.7 million possibilities, so repeats are rare, but at length 1 or 2 you will see them.
What the lengths are good for
| Length | Example | Typical use |
|---|---|---|
| 3 | #3C4 | Shorthand CSS color (#3C4 expands to #33CC44) |
| 6 | #8C9D0E | Standard RGB color code for CSS, design tools and charts |
| 8 | #8C9D0E80 | RGBA color in CSS with the last two digits as alpha (80 is 50% opacity) |
| 2 | #A7 | One random byte, 0 to 255 |
| 4 | #1A2B | Two bytes, such as a random port-sized value or a short test ID |
| 16 | #5C7D9E0F1A2B3C4D | 64-bit value for test data or a seed |
| 20 | #… | 80 bits, the longest this tool goes |
Lengths other than 3, 4, 6 and 8 are not valid CSS colors, so if you paste a five-digit result into a stylesheet it will be ignored. Strip the # if you need a bare hex value for code.
Hexadecimal in one paragraph
Hex is base 16. Each digit holds a value from 0 to 15, written 0–9 then A–F, and each pair of digits holds exactly one byte (0 to 255). That is why colors use six digits: two for red, two for green, two for blue. #FF0000 is full red, #000000 is black, #FFFFFF is white and #808080 is mid-gray. A random six-digit code is therefore a random point in the RGB cube, which is why most random colors look muddy. If you want pleasing palettes rather than uniformly random ones, generate ten and keep the two that work, or pick a length of 3 for a shorter search.
Ways to use it
- Placeholder colors. Filling chart series or wireframe boxes with distinct colors before a designer chooses real ones.
- Test data. Random hex IDs for fixtures, mock API responses and database seeds. Set the length to match your field.
- Teaching number bases. Generate two-digit values and have students convert them to decimal and binary. The Random Binary Number Generator covers the other side of that exercise.
- Quick contrast checks. Generate a batch of six-digit codes and test which pass as text on your background.
For random values in other formats, the site has a Random 6 Digit Number Generator for decimal codes, a Random Prime Number Generator and a Random Percentage Generator, all listed under all number generators.
Frequently asked questions
- Are the results valid color codes?
Only when the length is 3, 6 or 8 (and 4 for RGBA shorthand). Six digits is the standard web color. Other lengths are plain hex strings and will not work in CSS.
- Is the tool drawing from a database of colors?
No. Every digit is generated at random on the fly, so there is no fixed list and no limit on how many different values you can get.
- Can I get the same hex twice in one batch?
It is possible because each string is generated independently. At six digits the odds are about one in 16.7 million per pair, so in practice you will not see it; at one or two digits you will.
- Are these random hexes secure enough for keys or tokens?
No. They come from the browser's Math.random, which is fine for colors and test data but not for secrets. Use the Encryption Key Generator or a proper cryptographic library for anything security-related.



