Skip to content

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

Signatures:

Returns a CMYK color.

Available since v7.0.0

Returns: number[]

ts
function cmyk(): number[];

Examples

ts
faker.color.cmyk() // [0.31, 0.52, 0.32, 0.43]

colorByCSSColorSpace

Signatures:

Returns a random color based on CSS color space specified.

Available since v7.0.0

Returns: number[]

ts
function colorByCSSColorSpace(): number[];

Examples

ts
faker.color.colorByCSSColorSpace() // [0.93, 1, 0.82]

cssSupportedFunction

Returns a random css supported color function name.

Available since v7.0.0

Returns: 'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hwb' | 'cmyk' | 'lab' | 'lch' | 'color'

ts
function cssSupportedFunction(): CssFunctionType;

Examples

ts
faker.color.cssSupportedFunction() // 'rgb'

cssSupportedSpace

Returns a random css supported color space name.

Available since v7.0.0

Returns: 'sRGB' | 'display-p3' | 'rec2020' | 'a98-rgb' | 'prophoto-rgb'

ts
function cssSupportedSpace(): CssSpaceType;

Examples

ts
faker.color.cssSupportedSpace() // 'display-p3'

hsl

Signatures:

Returns an HSL color.

Available since v7.0.0

Returns: number[]

ts
function hsl(): number[];

Examples

ts
faker.color.hsl() // [201, 0.23, 0.32]

human

Returns a random human-readable color name.

Available since v7.0.0

Returns: string

ts
function human(): string;

Examples

ts
faker.color.human() // 'red'

hwb

Signatures:

Returns an HWB color.

Available since v7.0.0

Returns: number[]

ts
function hwb(): number[];

Examples

ts
faker.color.hwb() // [201, 0.21, 0.31]

lab

Signatures:

Returns a LAB (CIELAB) color.

Available since v7.0.0

Returns: number[]

ts
function lab(): number[];

Examples

ts
faker.color.lab() // [0.832133, -80.3245, 100.1234]

lch

Signatures:

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[]

ts
function lch(): number[];

Examples

ts
faker.color.lch() // [0.522345, 72.2, 56.2]

rgb

Signatures:

Returns an RGB color.

Available since v7.0.0

Returns: string

ts
function rgb(): string;

Examples

ts
faker.color.rgb() // '#8be4ab'

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

ts
function space(): string;

Examples

ts
faker.color.space() // 'sRGB'

Released under the MIT License.