Skip to Content
๐ŸŽฒ Welcome to RandBox - Powerful JavaScript Random Data Generation Library! Learn More

color

// usage randBox.color() randBox.color({format: 'hex'}) randBox.color({grayscale: true}) randBox.color({casing: 'upper'})

Return a random color in a random format.

randBox.color() => '#79c157'

Colors have six base types: hex, shorthex, rgb, rgba, 0x, name

These are the kinds usable in HTML or CSS. The type can optionally be specified

randBox.color({format: 'hex'}) => '#d67118' randBox.color({format: 'shorthex'}) => '#60f' randBox.color({format: 'rgb'}) => 'rgb(110,52,164)' randBox.color({ format:'rgba' }) => 'rgba(76,11,110,0.1284)' randBox.color({format: '0x'}) => '0x67ae0b' randBox.color({ format:'name' }) => 'DarkOrange'

Can optionally specify that only grayscale colors be generated

randBox.color({grayscale: true}) => '#e2e2e2'

Optionally specify casing to get only uppercase letters in the color

randBox.color({casing: 'upper'}) => '#29CFA7'
Last updated on: