Skip to content

Instantly share code, notes, and snippets.

@ahallora
Created July 27, 2017 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahallora/4960522c4739523513f044190ef94325 to your computer and use it in GitHub Desktop.
Save ahallora/4960522c4739523513f044190ef94325 to your computer and use it in GitHub Desktop.
Convert hex value to RGB value
function hexToRGBA (hex, opacity = 1) {
const components = hex
.replace('#', '')
.match(/.{1,2}/g)
.map(hextet => parseInt(hextet, 16))
.concat(opacity)
.join(', ');
return `rgba(${components})`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment