Skip to content

Instantly share code, notes, and snippets.

@schabluk
Created May 24, 2018 09:52
Show Gist options
  • Save schabluk/a679f4935c65783b8049389ecc1f91dc to your computer and use it in GitHub Desktop.
Save schabluk/a679f4935c65783b8049389ecc1f91dc to your computer and use it in GitHub Desktop.
HEX color to RGB with alpha
const hexToRGB = (hex, alpha) => {
const r = parseInt(hex.slice(1, 3), 16)
const g = parseInt(hex.slice(3, 5), 16)
const b = parseInt(hex.slice(5, 7), 16)
if (alpha) return `rgba(${r}, ${g}, ${b}, ${alpha})`
return `rgb(${r}, ${g}, ${b})`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment