Skip to content

Instantly share code, notes, and snippets.

@mkhoussid
Last active November 16, 2020 08:39
Show Gist options
  • Save mkhoussid/6998dc0a9424332d6c154c6143212f06 to your computer and use it in GitHub Desktop.
Save mkhoussid/6998dc0a9424332d6c154c6143212f06 to your computer and use it in GitHub Desktop.
Convert Hex color to RGBA format
export const hexToRgba = (rgbaColor: string, opacity: number): string =>
`rgba(${parseInt(rgbaColor.substring(1, 3), 16)}, ${parseInt(rgbaColor.substring(3, 5), 16)}, ${parseInt(
rgbaColor.substring(5, 7),
16,
)}, ${opacity})`;
// example usage:
// hexToRgba(#FFFFFF, 0.5) -> 'rgba(255, 255, 255, 0.5)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment