Color
Module to generate colors.
Overview
For a human-readable color like 'red', use human().
For a hex color like #ff0000 used in HTML/CSS, use rgb(). There are also methods for other color formats such as hsl(), cmyk(), hwb(), lab(), and lch().
cmyk
Returns a CMYK color.
Available since v7.0.0
Returns: number[]
function cmyk(): number[];
Examples
faker.color.cmyk() // [0.31, 0.52, 0.32, 0.43]
Source
colorByCSSColorSpace
Returns a random color based on CSS color space specified.
Available since v7.0.0
Returns: number[]
function colorByCSSColorSpace(): number[];
Examples
faker.color.colorByCSSColorSpace() // [0.93, 1, 0.82]
Source
cssSupportedFunction
Returns a random css supported color function name.
Available since v7.0.0
Returns: 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hwb' | 'cmyk' | 'lab' | 'lch' | 'color'
function cssSupportedFunction(): CssFunctionType;
Examples
faker.color.cssSupportedFunction() // 'rgb'
Source
cssSupportedSpace
Returns a random css supported color space name.
Available since v7.0.0
Returns: 'sRGB' | 'display-p3' | 'rec2020' | 'a98-rgb' | 'prophoto-rgb'
function cssSupportedSpace(): CssSpaceType;
Examples
faker.color.cssSupportedSpace() // 'display-p3'
Source
hsl
Returns an HSL color.
Available since v7.0.0
Returns: number[]
function hsl(): number[];
Examples
faker.color.hsl() // [201, 0.23, 0.32]
Source
human
Returns a random human-readable color name.
Available since v7.0.0
Returns: string
function human(): string;
Examples
faker.color.human() // 'red'
Source
hwb
Returns an HWB color.
Available since v7.0.0
Returns: number[]
function hwb(): number[];
Examples
faker.color.hwb() // [201, 0.21, 0.31]
Source
lab
Returns a LAB (CIELAB) color.
Available since v7.0.0
Returns: number[]
function lab(): number[];
Examples
faker.color.lab() // [0.832133, -80.3245, 100.1234]
Source
lch
Returns an LCH color. Even though upper bound of chroma in LCH color space is theoretically unbounded, it is bounded to 230 as anything above will not make a noticeable difference in the browser.
Available since v7.0.0
Returns: number[]
function lch(): number[];
Examples
faker.color.lch() // [0.522345, 72.2, 56.2]
Source
rgb
Returns an RGB color.
Available since v7.0.0
Returns: string
function rgb(): string;
Examples
faker.color.rgb() // '#8be4ab'
Source
space
Returns a random color space name from the worldwide accepted color spaces. Source: https://en.wikipedia.org/wiki/List_of_color_spaces_and_their_uses
Available since v7.0.0
Returns: string
function space(): string;
Examples
faker.color.space() // 'sRGB'