Generate attractive random colors

1.0.6 2022-10-13 11:40 UTC

This package is auto-updated.

Last update: 2024-06-13 15:30:23 UTC


PHP version

For generating attractive random colors.

This is a PHP port of David Merfield randomColor Javascript utility.

See the results on the demo.



You can pass an options object to influence the type of color it produces. The options object accepts the following properties:

hue – Controls the hue of the generated color. You can pass a string representing a color name (e.g. 'orange'). Possible color names are red, orange, yellow, green, blue, purple, pink and monochrome. You can also pass an array of multiple hues or a specific hue (0 to 360).

luminosity – Controls the luminosity of the generated color. You can pass a string containing bright, light or dark.

format – A string which specifies the format of the generated color. Possible values are hsv, hsl, hslCss, rgb, rgbCss, and hex.

prng – A random (or not) number generator. mt_rand is used as default one.


use \Colors\RandomColor;

// Returns a hex code for an attractive color

// Returns an array of ten green colors
RandomColor::many(10, array(
   'hue' => 'green'

// Returns a hex code for a light blue
   'luminosity' => 'light',
   'hue' => 'blue'

// Returns one yellow or blue color
    'hue' => array('yellow', 'blue')

// Returns a hex code for a 'truly random' color
   'luminosity' => 'random',
   'hue' => 'random'

// Returns a bright color in RGB
   'luminosity' => 'bright',
   'format' => 'rgbCss' // e.g. 'rgb(225,200,20)'

Other languages

RandomColor is available in JavaScript, C#, C++, Go, Haskell, Kotlin, Mathematica, Python, Swift, Perl6, Objective-C, Java, R, Reason, Dart, Ruby and Rust


This project is licensed under the terms of the MIT license.