Skip to content
On this page

Color

Module to generate colors.

cmyk

Returns a CMYK color.

Available since v7.0.0

Parameters

NameTypeDefaultDescription
options?{ ... }

Options object.

options.format?ColorFormat'decimal'

Format of generated CMYK color.

Returns: number[] | string

ts
faker.color.cmyk(options?: {
  format: ColorFormat
}): string | number[]
faker.color.cmyk() // => [0.55,0.59,0.72,0.85]
faker.color.cmyk() // [0.31, 0.52, 0.32, 0.43]
faker.color.cmyk({ format: 'decimal' }) // [0.31, 0.52, 0.32, 0.43]
faker.color.cmyk({ format: 'css' }) // cmyk(100%, 0%, 0%, 0%)
faker.color.cmyk({ format: 'binary' }) // (8-32 bits) x 4

colorByCSSColorSpace

Returns a random color based on CSS color space specified.

Available since v7.0.0

Parameters

NameTypeDefaultDescription
options?{ ... }

Options object.

options.format?ColorFormat'decimal'

Format of generated RGB color.

options.space?'a98-rgb' | 'display-p3' | 'prophoto-rgb' | 'rec2020' | 'sRGB''sRGB'

Color space to generate the color for.

Returns: number[] | string

ts
faker.color.colorByCSSColorSpace(options?: {
  format: ColorFormat,
  space: 'a98-rgb' | 'display-p3' | 'prophoto-rgb' | 'rec2020' | 'sRGB'
}): string | number[]
faker.color.colorByCSSColorSpace() // => [0.5488,0.5929,0.7152]
faker.color.colorByCSSColorSpace() // [0.93, 1, 0.82]
faker.color.colorByCSSColorSpace({ format: 'decimal' }) // [0.12, 0.21, 0.31]
faker.color.colorByCSSColorSpace({ format: 'css', space: 'display-p3' }) // color(display-p3 0.12 1 0.23)
faker.color.colorByCSSColorSpace({ format: 'binary' }) // (8-32 bits x 3)

cssSupportedFunction

Returns a random css supported color function name.

Available since v7.0.0

Returns: string

ts
faker.color.cssSupportedFunction(): string
faker.color.cssSupportedFunction() // => "hwb"
faker.color.cssSupportedFunction() // 'rgb'

cssSupportedSpace

Returns a random css supported color space name.

Available since v7.0.0

Returns: string

ts
faker.color.cssSupportedSpace(): string
faker.color.cssSupportedSpace() // => "a98-rgb"
faker.color.cssSupportedSpace() // 'display-p3'

hsl

Returns an HSL color.

Available since v7.0.0

Parameters

NameTypeDefaultDescription
options?{ ... }

Options object.

options.format?ColorFormat'decimal'

Format of generated HSL color.

options.includeAlpha?booleanfalse

Adds an alpha value to the color (RGBA).

Returns: number[] | string

ts
faker.color.hsl(options?: {
  format: ColorFormat,
  includeAlpha: boolean
}): string | number[]
faker.color.hsl() // => [198,0.59,0.72]
faker.color.hsl() // [201, 0.23, 0.32]
faker.color.hsl({ format: 'decimal' }) // [300, 0.21, 0.52]
faker.color.hsl({ format: 'decimal', includeAlpha: true }) // [300, 0.21, 0.52, 0.28]
faker.color.hsl({ format: 'css' }) // hsl(0deg, 100%, 80%)
faker.color.hsl({ format: 'css', includeAlpha: true }) // hsl(0deg 100% 50% / 0.5)
faker.color.hsl({ format: 'binary' }) // (8-32 bits) x 3
faker.color.hsl({ format: 'binary', includeAlpha: true }) // (8-32 bits) x 4

human

Returns a random human readable color name.

Available since v7.0.0

Returns: string

ts
faker.color.human(): string
faker.color.human() // => "salmon"
faker.color.human() // 'red'

hwb

Returns an HWB color.

Available since v7.0.0

Parameters

NameTypeDefaultDescription
options?{ ... }

Options object.

options.format?ColorFormat'decimal'

Format of generated RGB color.

Returns: number[] | string

ts
faker.color.hwb(options?: {
  format: ColorFormat
}): string | number[]
faker.color.hwb() // => [198,0.59,0.72]
faker.color.hwb() // [201, 0.21, 0.31]
faker.color.hwb({ format: 'decimal' }) // [201, 0.21, 0.31]
faker.color.hwb({ format: 'css' }) // hwb(194 0% 0%)
faker.color.hwb({ format: 'binary' }) // (8-32 bits x 3)

lab

Returns a LAB (CIELAB) color.

Available since v7.0.0

Parameters

NameTypeDefaultDescription
options?{ ... }

Options object.

options.format?ColorFormat'decimal'

Format of generated RGB color.

Returns: number[] | string

ts
faker.color.lab(options?: {
  format: ColorFormat
}): string | number[]
faker.color.lab() // => [0.548814,18.5689,43.0379]
faker.color.lab() // [0.832133, -80.3245, 100.1234]
faker.color.lab({ format: 'decimal' }) // [0.856773, -80.2345, 100.2341]
faker.color.lab({ format: 'css' }) // lab(29.2345% 39.3825 20.0664)
faker.color.lab({ format: 'binary' }) // (8-32 bits x 3)

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

Parameters

NameTypeDefaultDescription
options?{ ... }

Options object.

options.format?ColorFormat'decimal'

Format of generated RGB color.

Returns: number[] | string

ts
faker.color.lch(options?: {
  format: ColorFormat
}): string | number[]
faker.color.lch() // => [0.548814,136.4,164.5]
faker.color.lch() // [0.522345, 72.2, 56.2]
faker.color.lch({ format: 'decimal' }) // [0.522345, 72.2, 56.2]
faker.color.lch({ format: 'css' }) // lch(52.2345% 72.2 56.2)
faker.color.lch({ format: 'binary' }) // (8-32 bits x 3)

rgb

Returns an RGB color.

Available since v7.0.0

Parameters

NameTypeDefaultDescription
options?{ ... }

Options object.

options.casing?Casing'mixed'

Letter type case of the generated hex color. Only applied when 'hex' format is used.

options.format?'hex' | ColorFormat'hex'

Format of generated RGB color.

options.includeAlpha?booleanfalse

Adds an alpha value to the color (RGBA).

options.prefix?string'0x'

Prefix of the generated hex color. Only applied when 'hex' format is used.

Returns: number[] | string

ts
faker.color.rgb(options?: {
  casing: Casing,
  format: 'hex' | ColorFormat,
  includeAlpha: boolean,
  prefix: string
}): string | number[]
faker.color.rgb() // => "#cdfcdc"
faker.color.rgb() // '0xffffFF'
faker.color.rgb({ prefix: '#' }) // '#ffffFF'
faker.color.rgb({ casing: 'upper' }) // '0xFFFFFF'
faker.color.rgb({ casing: 'lower' }) // '0xffffff'
faker.color.rgb({ prefix: '#', casing: 'lower' }) // '#ffffff'
faker.color.rgb({ format: 'hex', casing: 'lower' }) // '#ffffff'
faker.color.rgb({ format: 'decimal' }) // [255, 255, 255]
faker.color.rgb({ format: 'css' }) // 'rgb(255, 0, 0)'
faker.color.rgb({ format: 'binary' }) // '10000000 00000000 11111111'
faker.color.rgb({ format: 'decimal', includeAlpha: true }) // [255, 255, 255, 0.4]

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
faker.color.space(): string
faker.color.space() // => "sYCC"
faker.color.space() // 'sRGB'

Released under the MIT License.