Generates a random hexadecimal color code.
Creates a pseudo-random color in the full RGB color space, returning a properly formatted 6-digit hex color string.
A random 6-character hexadecimal color code with leading #.
#
generateRandomHexColor();// => '#a3f29c' (or any random hex color) Copy
generateRandomHexColor();// => '#a3f29c' (or any random hex color)
// Using in a style contextconst backgroundColor = generateRandomHexColor();element.style.backgroundColor = backgroundColor; Copy
// Using in a style contextconst backgroundColor = generateRandomHexColor();element.style.backgroundColor = backgroundColor;
// Generating multiple random colorsconst palette = Array.from({ length: 5 }, () => generateRandomHexColor());// => ['#f4a123', '#82cd4e', '#1a2b3c', '#ff9900', '#abc123'] Copy
// Generating multiple random colorsconst palette = Array.from({ length: 5 }, () => generateRandomHexColor());// => ['#f4a123', '#82cd4e', '#1a2b3c', '#ff9900', '#abc123']
Generates a random hexadecimal color code.
Creates a pseudo-random color in the full RGB color space, returning a properly formatted 6-digit hex color string.