Random Hex Color Generator
Generate random hex color codes instantly. Copy hex values, preview swatches, build palettes, and export color collections for design projects.
About
Hex color codes encode red, green, and blue channels into a six-character string prefixed with #, where each pair ranges from 00 to FF (0 - 255 in decimal). The total color space contains 16,777,216 unique values (2563). Selecting colors by intuition alone introduces bias toward familiar hues and ignores large regions of the gamut. This generator uses crypto.getRandomValues to produce uniformly distributed samples across the full sRGB cube, eliminating the weak periodicity of pseudo-random number generators.
Relative luminance is computed for each swatch so overlay text automatically switches between light and dark for readability, following WCAG 2.1 contrast guidelines. The tool approximates perceptual brightness only; it does not account for display gamma calibration or wide-gamut color spaces like DCI-P3. Pro tip: if you need harmonious palettes rather than pure random samples, lock one hue channel and randomize the others.
Formulas
Each hex color encodes three channels. A random color is constructed by generating three independent bytes:
where R, G, B โ [0, 255] are unsigned 8-bit integers from crypto.getRandomValues.
To determine whether overlay text should be dark or light, relative luminance L is calculated per WCAG 2.1:
Each channel is linearized from sRGB:
where Csrgb = C255 for each channel. If L > 0.179, dark text is used; otherwise, light text is applied.
RGB to HSL conversion for the info display uses:
where Coffset depends on which channel is dominant, S = Cmax โ Cmin1 โ |2L โ 1|, and L = Cmax + Cmin2.
Reference Data
| Color Name | Hex Code | RGB | Luminance | Common Use |
|---|---|---|---|---|
| Black | #000000 | 0, 0, 0 | 0.000 | Text, borders |
| White | #FFFFFF | 255, 255, 255 | 1.000 | Backgrounds |
| Red | #FF0000 | 255, 0, 0 | 0.213 | Errors, alerts |
| Green | #00FF00 | 0, 255, 0 | 0.715 | Success states |
| Blue | #0000FF | 0, 0, 255 | 0.072 | Links, primary actions |
| Cyan | #00FFFF | 0, 255, 255 | 0.787 | Accents, info badges |
| Magenta | #FF00FF | 255, 0, 255 | 0.285 | Creative highlights |
| Yellow | #FFFF00 | 255, 255, 0 | 0.928 | Warnings |
| Orange | #FFA500 | 255, 165, 0 | 0.482 | CTAs, notifications |
| Purple | #800080 | 128, 0, 128 | 0.061 | Branding, luxury |
| Teal | #008080 | 0, 128, 128 | 0.170 | Healthcare, fintech |
| Navy | #000080 | 0, 0, 128 | 0.016 | Corporate, headers |
| Coral | #FF7F50 | 255, 127, 80 | 0.370 | Warm accents |
| Slate Gray | #708090 | 112, 128, 144 | 0.208 | Neutral text |
| Goldenrod | #DAA520 | 218, 165, 32 | 0.420 | Premium accents |
| Tomato | #FF6347 | 255, 99, 71 | 0.306 | Destructive actions |
| Steel Blue | #4682B4 | 70, 130, 180 | 0.206 | Dashboard UI |
| Mint Cream | #F5FFFA | 245, 255, 250 | 0.978 | Light backgrounds |
| Indigo | #4B0082 | 75, 0, 130 | 0.031 | Dark themes |
| Chartreuse | #7FFF00 | 127, 255, 0 | 0.648 | Eco, energy brands |