Skip to content
colors

randomColor

The `randomColor` function generates random colors with optional constraints for hue, saturation, lightness, alpha, and output format.

1 min read138 words

Function Signature

js

randomColor(options?: {
  format?: "hex" | "rgb" | "hsl" | "css",
  hue?: number | [number, number],
  saturation?: number | [number, number],
  lightness?: number | [number, number],
  alpha?: number | [number, number]
}): string | object

Parameters

  • format ("hex" | "rgb" | "hsl" | "css", optional): Output format. Defaults to "hex".
  • hue (number | [number, number], optional): Fixed hue or random hue range in degrees.
  • saturation (number | [number, number], optional): Fixed saturation or range in percent.
  • lightness (number | [number, number], optional): Fixed lightness or range in percent.
  • alpha (number | [number, number], optional): Fixed alpha or random alpha range from 0 to 1.

Return Value

A HEX string by default, or an RGB/HSL object when format is set to "rgb" or "hsl".

js

randomColor();
// "#3ba7f2"

randomColor({ hue: [180, 240], saturation: [60, 90], lightness: [45, 60] });
// constrained blue/cyan HEX

randomColor({ format: "hsl", hue: 24, saturation: [60, 90], lightness: [45, 55] });
// { h: 24, s: 74.2, l: 51.6 }

Usage Notes

  • random is exported as an alias of randomColor.
  • Use fixed ranges to generate consistent themed random colors.
  • If alpha is provided with format: "hex", the result is #rrggbbaa.

Previous

interpolate

Next

luminance


Top-Werkzeuge

BoardlyLinksyChromoCodeHub

ReadyTools

KarriereKontaktWerkzeuge
Preise7 Tage gratis
AnleitungenDocsBlogUpdatesLaraVault

Sprache wählen

Thema wählen

© 2026 ReadyTools. Alle Rechte vorbehalten.