Skip to main content
@spa-tools/utilities

hexToRgba

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

Usage

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

const rbgaColor = hexToRgba('#ff0000', 0.5);
console.log(rbgaColor);
// --> 'rgba(255, 0, 0, 0.5)'

Arguments

NameTypeRequired?DefaultDescription
hexstringyes-Hex color string
opacitynumberno1Opacity color value

Returns

string - The color in rgba format.