Skip to main content

rgbToHex

Callable

  • rgbToHex(color: string | Rgb): string

  • Converts an RGB(A) color strong or object to a hexadecimal color string.

    @example
    rgbToHex({ r: 255, g: 255, b: 255 }) // '#ffffff'
    rgbToHex('rgb(255, 255, 255)') // '#ffffff'
    rgbToHex('rgba(255, 255, 255, 0.5)') // '#ffffff80'

    Parameters

    • color: string | Rgb

      An object that represents an RGB color.

    Returns string

    A string that represents a hexadecimal color code.