Custom Hex Generator
Generate custom hexadecimal values, color codes, and random hex strings with prefix, length, case, and batch controls. Copy instantly.
About
Hexadecimal strings underpin nearly every layer of modern computing. Memory addresses, color definitions in CSS (#RRGGBB), cryptographic hashes, MAC addresses, and UUID fragments all rely on base-16 notation. A malformed hex value in a configuration file or API payload will silently corrupt data or trigger hard-to-trace parsing failures. This tool generates cryptographically secure hex values using crypto.getRandomValues rather than the predictable Math.random PRNG. You control length (up to 128 characters), character case, prefix, and batch quantity. The color mode validates output as a proper 3, 6, or 8-digit CSS hex color and renders a live swatch with computed WCAG contrast ratio.
Limitation: generated values are pseudorandom from the browser's CSPRNG. They are suitable for tokens, test data, and identifiers. They are not a replacement for a hardware entropy source in high-security key generation. The color contrast calculation assumes sRGB gamut and the standard L = 0.2126R + 0.7152G + 0.0722B relative luminance model per WCAG 2.0.
Formulas
Each hexadecimal character encodes exactly 4 bits of information. The total entropy of a hex string is:
where n = number of hex characters. The total number of possible unique values is:
For color mode, relative luminance L is computed per WCAG 2.0 to determine contrast against white and black text:
where each linearized channel Clin is derived from the sRGB value:
The WCAG contrast ratio between two luminances L1 and L2 (where L1 ≥ L2) is:
The random byte generation uses the Web Crypto API call crypto.getRandomValues(Uint8Array), which draws from the operating system's CSPRNG. Each byte is converted to a 2-character hex string via toString(16) with zero-padding.
Reference Data
| Hex Length | Bits of Entropy | Possible Values | Common Use Case |
|---|---|---|---|
| 1 | 4 | 16 | Single nibble, flags |
| 2 | 8 | 256 | Byte value, ASCII code |
| 3 | 12 | 4,096 | CSS shorthand color (#RGB) |
| 4 | 16 | 65,536 | Unicode code point (BMP) |
| 6 | 24 | 16,777,216 | CSS full color (#RRGGBB) |
| 8 | 32 | 4,294,967,296 | CSS color + alpha (#RRGGBBAA), IPv4 |
| 12 | 48 | 2.81 × 1014 | MAC address |
| 16 | 64 | 1.84 × 1019 | 64-bit identifier, API token segment |
| 32 | 128 | 3.40 × 1038 | MD5 hash, UUID (128-bit) |
| 40 | 160 | 1.46 × 1048 | SHA-1 hash, Git commit ID |
| 64 | 256 | 1.16 × 1077 | SHA-256 hash |
| 128 | 512 | 1.34 × 10154 | SHA-512 hash |
| Common Hex Color Codes | |||
| #FFFFFF | White - RGB(255, 255, 255) | ||
| #000000 | Black - RGB(0, 0, 0) | ||
| #FF5733 | Red-Orange - RGB(255, 87, 51) | ||
| #3498DB | Steel Blue - RGB(52, 152, 219) | ||
| #2ECC71 | Emerald - RGB(46, 204, 113) | ||
| #F39C12 | Sunflower - RGB(243, 156, 18) | ||
| #9B59B6 | Amethyst - RGB(155, 89, 182) | ||
| #1ABC9C | Turquoise - RGB(26, 188, 156) | ||