AnyTool
Your files never leave your device. All processing happens locally in your browser.

How do I generate a random color with its HEX, RGB and HSL codes?

Open AnyTool Random Color Generator, choose a style (any, pastel, vibrant, dark, light, grayscale, or a hue band), set how many swatches you want (1–24), and press Generate or the spacebar — each color is drawn from your browser’s crypto-secure randomness, never Math.random. Click a swatch to copy its HEX, or open the detail panel for every format (HEX, RGB, HSL, HSB, HWB, CMYK and CIELAB), the nearest CSS color name, and the WCAG contrast against black and white. Lock the colors you like and reroll the rest, then export the set as a HEX list, CSS variables or JSON. Nothing is uploaded.

  • Crypto-random colors (Web Crypto, no bias) — never Math.random
  • Every format: HEX, RGB, HSL, HSB/HSV, HWB, CMYK, CIELAB + nearest CSS color name
  • Constrain the style: any / pastel / vibrant / dark / light / grayscale / by hue
  • Lock favorites and reroll the rest · click to copy · spacebar to regenerate
  • Export as HEX list, CSS variables or JSON · WCAG contrast shown · 100% in your browser

What is

Random Color Generator

A random color generator produces one or more colors by drawing random values in a color space and presenting them in standard formats. AnyTool draws each color from the Web Crypto API and lets you constrain the distribution to a style (pastel, vibrant, dark, light, grayscale or a hue band), so the output ranges from fully random RGB to soft pastels or punchy saturated tones — each shown as HEX, RGB, HSL, HSB, HWB, CMYK and CIELAB with the nearest CSS color name.

Generators

Related terms

HEX colorRGBHSLCIELABWCAG contrastCrypto-secure random

Frequently Asked Questions

Yes. AnyTool draws every color from the Web Crypto API (crypto.getRandomValues) with rejection sampling, so the randomness is unbiased — it never uses Math.random.

Each color is generated with the browser’s Web Crypto API using rejection sampling, which removes modulo bias, so the random values are uniformly distributed — unlike the predictable Math.random many color tools rely on. In “any” mode the red, green and blue channels are each random across 0–255; the pastel, vibrant, dark, light and hue styles instead pick random hue, saturation and lightness within ranges chosen to produce that look, and grayscale picks a single random brightness. Everything runs in your browser, so no color is ever sent to a server.

HEX, RGB, HSL, HSB/HSV, HWB, CMYK and CIELAB, plus the nearest CSS color name — copy any of them with one click.

Click any swatch to copy its HEX instantly, or open the detail panel to copy the full set of formats: HEX, RGB, HSL, HSB (HSV), HWB, CMYK and CIELAB (L*a*b*). It also shows the nearest of the 147 extended CSS named colors, matched by perceptual CIELAB distance, so you get a human-readable label like “Coral” or “SteelBlue”. The whole set exports as a plain HEX list, CSS custom properties (:root variables), or JSON for use in code.

Yes. Click the lock icon on any swatch to keep it, then press Generate or the spacebar to reroll only the unlocked swatches.

Each swatch has a lock toggle. Lock the colors you want to keep and every Generate (or spacebar press) rerolls only the unlocked swatches, which lets you build up a set you like one color at a time. You can change the count from 1 to 24, switch the style at any point, copy individual colors, view a recent-colors strip of your last picks, and export the current set — all without losing your locked colors.

Random colors are great for inspiration but are not a harmonious scheme — use the Color Palette tool for that. Everything runs locally; nothing is uploaded.

A random set is perfect for inspiration, placeholders and backgrounds, but it is not a coordinated color scheme. For harmonious, theory-based palettes (complementary, analogous, triadic and so on) use AnyTool’s separate Color Palette tool, which is built for that. Before using a color for text or UI, check the contrast — the detail panel shows the WCAG ratio against black and white so you can confirm AA (4.5:1) or AAA (7:1). The generator runs entirely in your browser: colors, conversions, names and exports are computed locally and never uploaded, logged or stored, and it works offline once cached.

Detailed Explanation

Methodology

How the Random Color Generator Produces Each Color

AnyTool Random Color Generator creates every color in the browser using the Web Crypto API. Random values come from crypto.getRandomValues via rejection sampling — draws that would fall outside an even multiple of the range are discarded — so there is no modulo bias and the distribution is uniform; Math.random is never used. In the default “any” style each of the red, green and blue channels is an independent random value in 0–255. The style constraints instead sample in HSL: pastel uses high lightness with low–moderate saturation, vibrant uses high saturation at mid lightness, dark and light shift the lightness band, grayscale picks a single random brightness for all three channels, and “by hue” draws within a ±20° band around a chosen hue. Each generated color is converted client-side to HEX, RGB, HSL, HSB/HSV, HWB, CMYK and CIELAB, and labelled with the nearest CSS named color.

  • Colors come from crypto.getRandomValues (CSPRNG), not Math.random
  • Rejection sampling removes modulo bias — uniform random distribution
  • “Any” mode randomizes R, G, B in 0–255; styles sample hue/saturation/lightness
  • Converted to HEX, RGB, HSL, HSB, HWB, CMYK and CIELAB in the browser
  • All generation and conversion run client-side — no server round-trip
Use Cases

Formats, Nearest Color Name, Lock and Export

Click any swatch to copy its HEX, or open the detail panel to copy every format — HEX, RGB, HSL, HSB (HSV), HWB, CMYK and CIELAB — with one click each. The nearest color name is found by converting the color to CIELAB and choosing the closest of the 147 extended CSS named colors by Euclidean (ΔE76) distance, giving a readable label such as “Coral” or “SteelBlue”; it is the nearest match, not an exact one. A lock toggle on each swatch keeps colors you like while Generate or the spacebar rerolls only the unlocked swatches, so you can build a set incrementally; the count is adjustable from 1 to 24. The whole set exports as a plain HEX list, CSS custom properties (:root variables) or JSON, and a recent-colors strip records your last picks. Swatch text automatically switches between dark and light to stay readable on its background.

  • One-click copy of HEX, RGB, HSL, HSB, HWB, CMYK and CIELAB
  • Nearest of 147 CSS named colors by CIELAB distance (approximate, not exact)
  • Lock favorites and reroll only the unlocked swatches; 1–24 colors
  • Export as HEX list, CSS :root variables, or JSON
  • Contrast-aware swatch text and a recent-colors history strip
Limitations

When Random Colors Help — and When to Use a Palette Tool

A random color set is excellent for inspiration, placeholders, test data and backgrounds, but it is not a coordinated color scheme: random colors do not follow color-harmony relationships, so for complementary, analogous, triadic or other theory-based palettes you should use AnyTool’s separate Color Palette tool, which is purpose-built for harmonious schemes. Before using any color for text or interface elements, verify its contrast — the detail panel shows the WCAG contrast ratio against both black and white and whether it reaches AA (4.5:1) or AAA (7:1), because a visually pleasant color can still fail accessibility for text. The nearest-name label is a perceptual approximation rather than an exact named color. Everything is computed in your browser, so no color, conversion or export is sent to a server, logged or stored, and the tool works offline once cached.

  • Random colors aid inspiration but are not a harmonious palette
  • Use the separate Color Palette tool for complementary/analogous/triadic schemes
  • Check WCAG contrast (AA 4.5:1, AAA 7:1) before using a color for text
  • Nearest color name is an approximation, not an exact match
  • No uploads, logging or storage; works offline (PWA-cached); free, no account
Random color generator: in-browser (AnyTool) vs typical online color tools
CapabilityAnyToolTypical online color tools
RandomnessWeb Crypto CSPRNG, rejection sampling (no bias)Often Math.random
ProcessingRuns in your browserSometimes server-side
FormatsHEX, RGB, HSL, HSB, HWB, CMYK, CIELABOften just HEX/RGB/HSL
Color nameNearest of 147 CSS names by CIELAB distanceFrequently missing
Style constraintsAny / pastel / vibrant / dark / light / grayscale / by hueOften none or limited
Lock & rerollLock favorites, reroll the rest, 1–24 swatchesSometimes limited
Contrast checkWCAG ratio vs black & white (AA/AAA) shownUsually absent
ExportHEX list, CSS variables, JSONOften copy-one-only
PrivacyNever uploaded, not stored, works offlineMay transmit or log
Cost / signupFree, no signupOften ad-heavy or gated

AnyTool generates every color locally with crypto-secure randomness, converts to seven formats with a nearest color name, and uploads nothing.