Skip to main content
Back to Numbers generators

Numbers

Random Hex Code Generator

Used by developers, writers, and creators worldwide.

A random hex code generator gives developers, designers, and security engineers valid hexadecimal strings on demand. Hex codes appear throughout computing — CSS colors, OAuth secrets, session tokens, memory addresses, and UUID components all rely on base-16 format. Typing them by hand is slow and error-prone. This tool lets you control string length, 0x prefix, casing, and batch size. A 6-char lowercase string produces a CSS color like `a3f2c1`. A 32-char uppercase string works as a mock API key or cryptographic seed placeholder. Need 0x-prefixed literals for C or JavaScript? Toggle the prefix option and your output is paste-ready. Generate a batch, copy the list, and move on.

Loading usage…

Free forever — no account required

How to use

  1. Choose your options above
  2. Click Generate
  3. Copy your result

Detailed instructions

  1. Set the length field to match the hex string size you need — 6 for colors, 32 for tokens.
  2. Choose whether to include the 0x prefix based on where the output will be pasted.
  3. Select uppercase or lowercase to match the convention of your target system.
  4. Set the count to the number of hex strings you need, then click Generate.
  5. Copy individual strings or the full list and paste directly into your code, file, or tool.

Use Cases

  • Generate 0x-prefixed hex literals to paste directly into C or JavaScript source code
  • Create random CSS hex colors for rapid palette exploration in Figma or a stylesheet
  • Populate a Jest fixture file with 32-char uppercase mock API keys and OAuth secrets
  • Seed a Postgres staging database with realistic hex identifier strings for 200 test users
  • Produce 64-character SHA-256-style hash placeholders for API documentation and diagrams

Tips

  • For bulk palette testing, generate 20+ six-character codes and paste them into a CSS file to preview random color distributions quickly.
  • When populating fixture or seed files, match the exact length of real IDs in your system to avoid type or validation errors during testing.
  • Lowercase hex is safer for URLs and JSON keys since some parsers are case-sensitive about string matching.
  • Generate a batch of 0x-prefixed uppercase strings when writing hardware register documentation or writing assembly pseudocode examples.
  • To simulate UUID-like identifiers, generate 32-character lowercase strings and insert hyphens after positions 8, 12, 16, and 20 in a text editor.
  • If you need pairs of hex values — for example, a key and an initialization vector — generate double your count and split the list in two.

FAQ

how do I generate a random CSS hex color code

Set length to 6, prefix to No, and uppercase to No. Each result is a valid CSS hex color like `a3f2c1` — just prepend a `#` before pasting into your stylesheet. Generate 20 or 30 at once to build a raw palette you can evaluate quickly.

are these hex codes safe to use as cryptographic secrets

This generator uses browser-based pseudorandom generation, which is fine for testing and mock data but not for production secrets. For real cryptographic material, use `crypto.getRandomValues()` in Node.js or `secrets.token_hex()` in Python instead.

what length should I use for different hex applications

Use 6 characters for CSS colors, 16 for session tokens or nonces, 32 for mock API keys or MD5-style placeholders, and 64 for SHA-256-style hash stand-ins. When matching an existing system, count the characters in a real example and match that length exactly.