Random Color Generator – Random Colors and Color Palettes with HEX Codes

Press the space bar or the button and get a random color, or a palette of five that work together.

Press the space bar to generate new colors. Lock a color to keep it.

Each swatch shows its HEX, RGB, HSL and OKLCH codes, and a click copies the one you need. Lock a color you like and the others keep changing around it. Palette types include analogous, complementary, triadic and monochrome, all built in a perceptual color space so the steps look even. Under every swatch you see its WCAG contrast ratio with white and black text, so you know right away whether a button or a heading in that color will be readable. Your last palettes stay in this browser, and the link holds the current one for sharing.

How it works

Random colors are picked in OKLCH, the perceptual color space CSS now supports with oklch(). It has three numbers: lightness (L, 0 to 100%), chroma (C, how colorful) and hue (H, an angle from 0 to 360). Unlike HSL, equal steps in OKLCH look like equal steps to the eye: a yellow and a blue with the same L really look equally light. The generator draws L between 35% and 92%, chroma between 0.04 and 0.22 and any hue, using crypto.getRandomValues, so you get usable colors rather than mud or neon. Palettes start from one base hue. Analogous shifts it by 25 and 50 degrees either way. Complementary adds the hue opposite (plus 180 degrees). Triadic uses three hues 120 degrees apart. Monochrome keeps the hue and steps the lightness from dark to light. A locked color becomes the base, so the rest fit around it. When a color falls outside what a screen can show (the sRGB gamut), the generator lowers the chroma until it fits and keeps the hue and lightness. Contrast follows WCAG 2. Each sRGB channel is converted to linear light, then the relative luminance is L = 0.2126 R + 0.7152 G + 0.0722 B, from 0 for black to 1 for white. The contrast ratio of two colors is (lighter + 0.05) / (darker + 0.05), from 1:1 to 21:1. Normal text needs 4.5:1 for level AA and 7:1 for AAA; large text (24 px, or 18.66 px bold) needs 3:1.

Worked example

You press the space bar and get #1E90FF, a bright sky blue. Its other codes are rgb(30 144 255), hsl(210 100% 56%) and oklch(65.2% 0.190 253.2). Can you put white text on it? Its relative luminance is 0.2744. Against white (luminance 1) the ratio is (1 + 0.05) / (0.2744 + 0.05) = 3.24:1. That passes only for large text, so the swatch says "AA large text only". Against black (luminance 0) it is (0.2744 + 0.05) / (0 + 0.05) = 6.49:1, which passes AA. For a button label in this blue, black text is the safe choice, or a darker blue behind white text. You lock the blue and switch the palette type to Complementary. The four other swatches change: two lighter and darker blues, and two warm colors on the opposite side of the wheel, around hue 73 in OKLCH. Press space until you like them, then Copy as CSS variables gives you --color-1 to --color-5 ready to paste.

Frequently asked questions

How do I generate a random color?

Press the space bar or Generate colors. Choose One color in How many for a single swatch, or keep Palette of 5. Click any code to copy it.

How do I keep a color I like?

Press the lock on its swatch. Locked colors stay when you generate again, and in a palette mode the new colors are built around the first locked one.

What is the difference between HEX, RGB, HSL and OKLCH?

HEX and RGB give the red, green and blue amounts (HEX in base 16). HSL describes hue, saturation and lightness, but its lightness does not match what the eye sees. OKLCH is a perceptual space: the same lightness value looks equally light whatever the hue. All four work in CSS.

What contrast ratio do I need for text?

WCAG 2 asks for at least 4.5:1 for normal text (level AA) and 7:1 for AAA. Large text, 24 px or 18.66 px bold, needs 3:1. The lines under each swatch show the ratio with white and with black text.

What do complementary and analogous colors mean?

Complementary colors sit opposite each other on the color wheel, 180 degrees apart, and contrast strongly. Analogous colors are neighbors, here 25 and 50 degrees apart, and look calm together. Triadic uses three hues 120 degrees apart.

Can I share a palette?

Yes. The address always holds the current colors, the palette type and the locks. Use Copy link to send it, and the other person sees the same palette.