hexToRGBA

hexToRGBA is a utility function that converts a hex color to an RGBA color.

Import

import { hexToRGBA } from '@contentful/f36-utils';

Example

Basic usage

import tokens from '@contentful/f36-tokens';
const color = hexToRGBA(tokens.colorBlack);
console.log(color);
// rgba(0, 0, 0, 1)
const colorWithOpacity = hexToRGBA(tokens.colorBlack, 0.5);
console.log(colorWithOpacity);
// rgba(0, 0, 0, 0.5)

Help improve this page