Skip to main content

getHexFromRgb()

function getHexFromRgb(options): string

Converts an RGB color to a hexadecimal color code.

Parameters

ParameterTypeDescription
optionsobjectThe options for converting RGB to hex.
options.bnumberThe blue component of the RGB color (0-255).
options.gnumberThe green component of the RGB color (0-255).
options.rnumberThe red component of the RGB color (0-255).

Returns

string

The hexadecimal color code.

Throws

If any RGB component is outside the valid range (0-255).

Example

getHexFromRgb({ r: 255, g: 0, b: 0 });
// Returns '#ff0000'

Defined in

rgb/rgb.ts:111