Random & Generators

Random Color Generator

Generate up to 24 random colors at once, in any style, with HEX, RGB and HSL codes and a contrast check for each one.

Free, runs in your browserUpdated October 2026HEX, RGB, HSLWCAG contrastBy Talha Salman
colors
1 to 24 at a time.
Show codes as
Selected color
–
Contrast = (L1 + 0.05) ÷ (L2 + 0.05)
RGB–
HSL–
Contrast with white text–
Contrast with black text–

Quick answer: This random color generator creates 1 to 24 random colors at once and gives each one as HEX, RGB and HSL, with its contrast against white and black text. A fully random HEX code is a random whole number from 0 to 16,777,215 written in base 16, so #4080BF is rgb(64, 128, 191).

Random color generator diagram: a random number becomes a HEX code, split into red, green and blue values, with swatches for pastel, vivid, dark and grayscale styles
How a random number becomes a HEX color, and how styles narrow the range.

What Is a Random Color Generator?

A random color generator is a tool that picks colors by chance and shows their codes, so you can break out of the same few shades you always reach for. Designers use it for fresh starting points, developers for placeholder and chart colors, and teachers or game hosts to assign team colors without arguments.

Choose Any color to draw from all 16,777,216 colors a screen can show, or pick a style such as pastel, vivid, dark, muted, warm, cool or grayscale. Each swatch can be locked, so you keep the colors you like and reroll the rest. When you want colors that are designed to work together rather than random ones, the color palette generator builds harmony schemes from one base color.

How Do You Generate Random Colors?

How to use the random color generator: set the number of colors, choose a style and code format, press Generate, then lock or inspect swatches
Set the count and style, generate, then lock or inspect any swatch.
  1. Enter how many colors you want, from 1 to 24.
  2. Choose a color style, or leave it on Any color for a completely random pick.
  3. Choose whether the swatches show HEX, RGB or HSL codes.
  4. Press Generate colors, or press the space bar while the swatches are on screen. Tap a swatch to copy its code and see its details, and tap Lock on any swatch to keep it for the next round.

Copy all puts every code on its own line, ready to paste into CSS, a design file or a spreadsheet. To fine-tune one of the results by eye, open it in the color picker.

How Is a Random HEX Color Made?

A random HEX color is made by picking a whole number from 0 to 16,777,215 (that is 256 × 256 × 256 − 1) and writing it as six hexadecimal digits. The first two digits are red, the middle two are green and the last two are blue, each from 00 to FF.

n = random integer from 0 to 16,777,215
Red = floor(n ÷ 65,536), Green = floor(n ÷ 256) mod 256, Blue = n mod 256
HEX = # + Red, Green and Blue as two hex digits each

Worked example: n = 4,227,263 gives Red = 64, Green = 128 and Blue = 191, which is #4080BF, a medium blue. The styles work differently: they pick a random hue, saturation and lightness inside a set range, then convert that HSL color to RGB using the method in the W3C CSS Color Module Level 4. If you already have RGB values and only need the code, the RGB to HEX converter does that step.

StyleHueSaturationLightnessExample
PastelAny55 to 85%78 to 90%#B2EEC9
Bright and vividAny85 to 100%45 to 58%#F65123
DarkAny40 to 85%12 to 28%#235433
Muted and earthyAny12 to 38%35 to 65%#8C7B66
Warm330° to 60°65 to 95%45 to 62%#EBD643
Cool170° to 280°45 to 90%38 to 62%#3D8FD1
GrayscaleNone0%6 to 94%#5B5B5B

Which Text Color Works on a Random Color?

The text color that works best is whichever of black or white gives the higher contrast ratio, and the tool picks it for every swatch automatically. Contrast is worked out from the relative luminance of each color, as defined in the W3C WCAG 2.2 contrast ratio definition.

Contrast ratio = (L1 + 0.05) ÷ (L2 + 0.05)
L = 0.2126 R + 0.7152 G + 0.0722 B (linear RGB values)

Black on white scores the maximum of 21:1. Normal text needs at least 4.5:1 to pass level AA and 7:1 for AAA, while large text needs 3:1. For example, mid gray #777777 on white scores 4.48:1, which just fails AA for body text, so a random color that looks readable is worth checking before you use it for buttons or labels.

Frequently asked questions

How many possible random colors are there?

There are 16,777,216 colors in standard 24-bit RGB, because each of red, green and blue has 256 levels and 256 × 256 × 256 = 16,777,216. Any color mode can return every one of them with equal chance.

How do I keep a color I like?

Tap Lock on that swatch. Locked colors stay in place when you press Generate again, and only the unlocked swatches change.

What is the difference between HEX, RGB and HSL?

They describe the same color in different ways. HEX writes red, green and blue as hexadecimal pairs, RGB writes them as numbers from 0 to 255, and HSL describes hue in degrees with saturation and lightness as percentages.

How do I generate random pastel colors?

Set Color style to Pastel. The tool keeps lightness between 78% and 90% and saturation between 55% and 85%, which gives soft, light colors in every hue.

Is black or white text better on a random color?

It depends on the color's luminance. The tool compares both contrast ratios and labels each swatch with the better one, along with whether it passes WCAG AA or AAA.