Skip to main content
@spa-tools/utilities

rgbaToHex

The rgbaToHex function converts an rgba color string to a hex color string.

Usage

import { rgbaToHex } from '@spa-tools/utilities';

const hexColor = rgbaToHex('rgba(255, 0, 0, 0.5)');
console.log(hexColor);
// --> '#ff000080'

Arguments

NameTypeRequired?DefaultDescription
rgbastringyes-RGBA color string
opacitynumberno1Opacity color value

Returns

string - The color in hex format.