showing results for - "javascript hex color to rgba"
Romy
29 Jan 2019
1hexToRGB(hex: string, alpha: string) {
2
3  const r = parseInt(hex.slice(1, 3), 16);
4  const g = parseInt(hex.slice(3, 5), 16);
5  const b = parseInt(hex.slice(5, 7), 16);
6
7  if (alpha) {
8    return `rgba(${r}, ${g}, ${b}, ${alpha})`;
9  } else {
10    return `rgb(${r}, ${g}, ${b})`;
11  }
12}
Madeleine
08 Sep 2020
1//If you write your own code, remember hex color shortcuts (eg., #fff, #000)
2
3function hexToRgbA(hex){
4    var c;
5    if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){
6        c= hex.substring(1).split('');
7        if(c.length== 3){
8            c= [c[0], c[0], c[1], c[1], c[2], c[2]];
9        }
10        c= '0x'+c.join('');
11        return 'rgba('+[(c>>16)&255, (c>>8)&255, c&255].join(',')+',1)';
12    }
13    throw new Error('Bad Hex');
14}
15
16hexToRgbA('#fbafff')
17
18/*  returned value: (String)
19rgba(251,175,255,1)
20*/
21
queries leading to this page
hex to rgb javascriptjavascript get rgba and hex colorsjs rgba colorjavascript rgbahow to use rgba color in jsnpm hex to rgbajs hex to rgba converterjs background color rgbargba to hex converter javascriptconvertir color hx a rgb en javascripthow to convert rgba to hex in javascriptget rgba color javascriptjs rgb alpha to hexjavascript rgba string to hexconvert rgba color code to hex javascriptcolor not working with rgba in jsjs hex to rgbargba color use in javascriptset rgba color in javascriptjs rgba to rgbhow use rgba color javascript color propertyjavascript hex color to rgbaadd alpha to rgba from hex javascriptjs color number to rgbaget rgba to hex 8 javascripthex to rgba javascriptjs hex color to rgbhow use rgba color code with javascript color propertyjavascript css rgbacolor js rgbargba to hex in jsconvert rgba to hex javascriptjavascript convert hex to rgbahexa to rgba javascripthex to rgba in jsconver rgba to hexa by javascriptrgba color javascriptjavascript rgba pass hexhex color to rgba colorhex code to rgba javascriptfunction get color rgba javascriptrgb background color jsjavascript rgba to hexrgba color jscolor hex rgba codergba to hex javascriptjavascript rgb to rgbajavascript hex to rgbabackground color rgba javascriptjs convert hex to rgbahex color to rgba javascriptjavascript convert html color code to rgbajavascript set background color rgbargba to hex jshow to give rgba color in javascriptjs hex color to css rgbargba color in jsrgba to rgb value javascriptjquery rgba to hexget rgba from hex javascriptbackground color javascript rgbajs rgba to hexrgb to rgba javascripthex to rgba jsconvert a rgba color to hex in javascriptcan i convert color in rgba in javascriptjs hex color to rgbajavascript style backgroundcolor rgbachart js rgba colorjavascript hex with alpha to rgbjavascript rgba colorjavascript hex color to rgba