goldies
    Preparing search index...

    Function generateRandomHexColor

    • 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.

      Returns string

      A random 6-character hexadecimal color code with leading #.

      generateRandomHexColor();
      // => '#a3f29c' (or any random hex color)
      // Using in a style context
      const backgroundColor = generateRandomHexColor();
      element.style.backgroundColor = backgroundColor;
      // Generating multiple random colors
      const palette = Array.from({ length: 5 }, () => generateRandomHexColor());
      // => ['#f4a123', '#82cd4e', '#1a2b3c', '#ff9900', '#abc123']