Beginner

Random Color Generator

Generate one or more random colors and instantly read their HEX, RGB and HSL codes plus the best overlay text color.
1 to 12

Hue mode

Red channel value
47

Primary color: #2F27A8

HEX
#2F27A8
RGB
rgb(47, 39, 168)
HSL
hsl(244, 62%, 41%)
Relative luminance
0.049
Suggested text color
White
Colors generated
1
Red47
Green39
Blue168
Results are estimates for general information only and are not professional advice — always verify important results independently before relying on them. Read the full disclaimer.
Quick answer

How does this calculator work?

A random color generator picks red, green and blue values from 0 to 255 to form a color, then shows it as HEX, RGB and HSL. It also computes the color's relative luminance and suggests black or white text for readable contrast. Choose a count and a hue mode to bias the palette warm, cool or pastel.

Formula
R,G,B = floor(random() × 256); HEX = '#' + hex(R) + hex(G) + hex(B); luminance = 0.2126·R' + 0.7152·G' + 0.0722·B'
How this is calculated

The "How many colors" input controls how many independent random colors are produced (clamped to 1-12), and the "Hue mode" select shapes the random distribution. In "any" mode each of the red, green and blue channels is an independent integer from 0 to 255, giving a uniform random color across the full 24-bit space. "Warm", "cool" and "pastel" modes instead pick a hue, saturation and lightness in restricted HSL ranges and convert that back to RGB, so colors stay in a recognisable family.

Each color is reported three ways. HEX is built by converting every channel to a two-digit base-16 string and joining them after a "#". HSL is derived from the normalized channels: hue comes from which channel is the maximum, lightness is the average of the largest and smallest channels, and saturation is the channel spread divided by 1 - |2L - 1|. These are equivalent representations of the same color.

The suggested text color uses WCAG relative luminance. Each channel is normalized to 0-1 and linearized with the sRGB transfer curve, then combined as 0.2126·R + 0.7152·G + 0.0722·B. If that luminance exceeds about 0.179 the background is "light" and black text is recommended, otherwise white text gives better contrast. Because colors are random, results change on every recalculation.

Frequently asked questions

They are three notations for the same color. RGB lists the red, green and blue intensities (0-255), HEX is the same values written in base 16, and HSL describes the color by hue, saturation and lightness.

It compares the color's relative luminance to a threshold (~0.179). Brighter backgrounds get black text and darker backgrounds get white text, which keeps the text readable per WCAG contrast guidance.

They restrict the random hue, saturation and lightness ranges: warm favors reds, oranges and yellows, cool favors greens, blues and purples, and pastel keeps saturation low and lightness high for soft tints.

Also known as

hex color generator
random hex
rgb generator
color picker
random palette
random colour
hex code generator
random color picker

APA

TG we-Calculate Editorial Team. (2026). Random Color Generator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/random-color-generator

Chicago

TG we-Calculate Editorial Team. "Random Color Generator." TG we-Calculate. 2026. https://we-calculate.com/calculator/random-color-generator.

IEEE

TG we-Calculate Editorial Team, "Random Color Generator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/random-color-generator

BibTeX

@misc{wecalculate_random_color_generator, title = {Random Color Generator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/random-color-generator}}, year = {2026}, note = {TG we-Calculate} }

Did this calculator help you?