Skip to main content

Function: rgbToHex()

rgbToHex(rgb, includeAlpha?): string

Converts RGB values to a hex color code.

Parameters

ParameterTypeDefault valueDescription
rgbRGBundefinedAn object with r, g, and b properties, and an optional a property.
includeAlpha?booleanfalseWhether to include the alpha channel in the hex string.

Returns

string

The hex color code.

Throws

If the input is not a valid RGB object or if RGB values are out of range.

Defined in

conversions/components/hex.ts:10