Skip to main content

Function: hex2rgba()

hex2rgba(hex, alpha?): undefined | string

Defined in: utils/colors/index.ts:53

hex2rgba

Parameters

hex

string

The hex color code (e.g., '#fff' or '#ffffff').

alpha?

number

An optional alpha value (0-1).

Returns

undefined | string

The rgba or rgb string, or undefined if the hex is invalid.

Description

Converts a 3 or 6-digit hex color code to an rgba or rgb string.

Example

hex2rgba('#fff', 0.5) // 'rgba(255, 255, 255, 0.5)'