showing results for - "hex to rgb function"
Aminata
16 May 2019
1function rgbToHex(r, g, b) {
2  return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
3}
4
5function hexToRgb(hex) {
6  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
7  if(result){
8      var r= parseInt(result[1], 16);
9      var g= parseInt(result[2], 16);
10      var b= parseInt(result[3], 16);
11      return r+","+g+","+b;//return 23,14,45 -> reformat if needed 
12  } 
13  return null;
14}
15console.log(rgbToHex(10, 54, 120)); //#0a3678
16console.log(hexToRgb("#0a3678"));//"10,54,120"
Isabell
21 Jul 2018
1function hexToRgb(hex) {
2  // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF")
3  var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
4  hex = hex.replace(shorthandRegex, function(m, r, g, b) {
5    return r + r + g + g + b + b;
6  });
7
8  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
9  return result ? [
10    parseInt(result[1], 16),
11    parseInt(result[2], 16),
12    parseInt(result[3], 16)
13  ] : null;
14}
15
16alert(hexToRgb("#0033ff").g); // "51";
17alert(hexToRgb("#03f").g); // "51";
Jonas
06 Feb 2017
1function hexToRgb(hex) {
2  var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
3  return result ? {
4    r: parseInt(result[1], 16),
5    g: parseInt(result[2], 16),
6    b: parseInt(result[3], 16)
7  } : null;
8}
9
10alert(hexToRgb("#0033ff").g); // "51";
Anael
11 Jun 2020
1function componentToHex(c) {
2  var hex = c.toString(16);
3  return hex.length == 1 ? "0" + hex : hex;
4}
5
6function rgbToHex(r, g, b) {
7  return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
8}
9
10alert(rgbToHex(0, 51, 255)); // #0033ff
Calliope
08 Oct 2019
1function hex2RGB(hex){
2        const r = parseInt(hex.substring(1, 3), 16);
3        const g = parseInt(hex.substring(3, 5), 16);
4        const b = parseInt(hex.substring(5, 7), 16);
5        return `${r}, ${g}, ${b}`;
6}
queries leading to this page
javascript convert rgb to hex in style propertyjavascript hex color to rgbjavascript convert hex code to htmlhow to convert rgb to hex in javascriptjs convert rgbr to hexblue to hex jsjavascript get rgb values from hexconvert rgb to hex javascript functionjavascript hex code to rgbconvert rgb to hex jsrgb to hex conversion coldwars javascriptfrom rgb to hex jsconvert from hex to rgb jshex to rgb in javascriptjs for converting hex to rgbhow to convert hex to rgb in javascriptrgba to hex javascriptmapping from decimal to hex javascript colorhow to get only the red value in the rgb with javascriptconvert hex color to rgb in jsone color rgb to hex jsjavascript rgb to hex conversion 5 kyuhexcolor to rgbjavascriptrgb to hex jsjs hex to rgba converterjavascript convert number in color to rgbjs rgb from hexhow to convert hex into rgb color in javascriptjs hex character to rgbconvert rgb value to hex javascriptjavascript rgb to stringjavascript color string to rgbhex to rgba converterconvert that hex color code to rgb and return it as an array 5br 2c g 2c b 5d javascripthex to rgba convert javascriptchange hex to rgb jsjavascript convert a hex string to rgbconvert rgb to hex javascriptdiscord js color with rgbhex color to rgb javascripthexadecimal to rgb jsconvert hex to rgb javascript functionhow to convert rgb to hex javascriptrgb to hsl javascripthex to srgb jsjs hex to rgb converterhow to convert a hex number to rgb value javascriptconvert rgb to hex in javascriptconvert hex color to rgb jsjs rbg to hexfrom rgb to hex javascriptjs return rgb value from rangehex to rgb converter jsjavascript rgb to hecjavascript convert rgb string color to hexget hex to rgb javascriptcolor to rgb jsjs rgb to hex why 16convert rgb color object into number jsconvert rgb string to hex javascripthow to change rgb to hex javascriptfrom hex to rgbjavascript hex to rgbajs convert hex to rgbajs hex to rgb colorhow to convert hex to rgb javascript3 rgb numbers to hex node jshex to rgb and rgb to hex javscripthex to rgbajs convert rgb to hexadecimalde hexadecimal a rgb jshexa to rgbhextorgbarrayjs get convert color to rgbconvertir color hx a rgb en javascriptjavascript get rgb from hexrgb to decimal code javscriptrgb to hexjavascripthex to rgb functionhex code to rgb function javascriptconvert rgb to hsl javascripthex to rgb mathconvert pantone to rgb 2bjavascriptconvert hexa to rgb javascriptjavascript hex inverterhex codes to rgbconvert rgb to hex javascriptpacreturn rgb int from hexrgb to 23 javascriptjs comvert rgb to hexjavascript convert color from hex to rgbget decimal color from hex javascriptreact diseable convert code color to rgbjavascript convert hexadecimal to rgbconvert hex code to rgb javascripttypescript rgb to hexconvert color hex to rgb jshex to rgb convert javascriptconvert rgba to hex javascript onlinefunction from hex to rgb reactjs hex array to rgbjavascript rgb to exadecimaleconver rgb to hex color jsjs color rgb to hergb color to hex javascriptjs color number to rgbjs how to convert rgb to hexconvert hash color to rgb with javascriptjavascript rgbrgb to hex javascriptjavascript hex to rbconvert rbg a to hex jsrgb2hex javascriptconvert rgb hex to rgb javascripthex to rgb javascript functionjs convert code to hexcolorrrs hex to rgb rgb to hex in jsjavascript convert rbg to hexhex rgb converter javascriptrgb to hex in javascripthexidecimal to rgbrgb to color jshow to convert an r 2c g 2c and b to a hex code in jsconvert 23rrggbb to 23rgb jscolor rgb to hex jshow to convert rgb colors to hexadecimal with javascriptrgb 28 29 to hex jsconvert color to rgb javascriptconvert rgb to hex color javascriptjavascript how to convert hex to rgbfind the whole spectrum of a hex color jscolor hex to rgbjavascript rpg to hexhow to combine rgb to hexa javafrom rbg 28r 2cg 2cb 29 to int jshex to rgbsjavascript rgb to hex codejavascript function to convert hex to rgbhow to convert color to rgb with javascriptjs rgb to hex colorrgb to hexadecimal javascriptrgb color typescriptrgb decimal to hex javascriptconvert regb to hex angularget rgb from hex javascriptif i set hex color by java it converted to rgb automatically why 3frgb string to hex converter javascriptcss hex to rgb functionsimple rgb to hex jsjavascript rgb to hexadecimalrgb to hex conversion javascriptcolor from hex to rgbjshex to rgbparse hex into color jsrgb string to hex in javascriptreturn 28 colordigits map 28c 3d 3e 60 24 7bc 3c 10 3f 270 27 3a 27 27 7d 24 7bc tostring 2816 29 7d 60 29 join 28 27 27 29 29js convert color hex code to rgbhex to rgb conversion javascriptjavascript hrx to rgbconvert rgb to hex javascript onlinehex to rgbojavascript convert number in rgbrgb zu hexjavascript rgba to hexhow to convert hex into rgba in jsrgb to hex js codehex color to rgbacolor code hex to rgbtypescript convert color to hexrgb to hex javascript functionhex to rgb color typescriptconvert r g b to hex javascriptnode js hex to rgbconvert rgba to hex javascripthex to rgb javascripthex to rgb js javascript to convery hex to rgbargb to hex color javascripttransform rgb to hex javascripttypescript rgb to hex converthex to rgb converterrgb to hex valuesrgb to hex converter javascriptconvert hex to rgbconvert rgba to hex in jshex to rgba javascripthextorgb js not foundtransform hex to rgb jsrgb para hexadecimal jsrgb to hex colorconverting rgb value to hexcodei n jsjavascript function rgb to hexrgb to hex jaavscriptfrom hexadecimal to color jsjavascript convert rgb color as hexjs hex to rgbrgb to hex function javascriptargb to hexjs convert hex string into rgbfunction hex to rgb stack overflowjs rgb to hexjs go from green to red as object gets largerfrom rgba hexhex rgba to hextypescript hex to rgbhex colour to rgb jsjs convert hex into rgb and hsljavascript rgba string to hexhex characters to rgb jscovert hex to rgb jscolor hex to rgb jsfunction to convert color rgbconvert hex color to rgb javascript and returns its an arryhex to srgb hex jsfunction to convert rgb to hexhow to convert 8 digit hex to rgb in javascriptcolor to hex jsjs style rgb to hexhextorgb jsrgb to hex conversion javascript codewarsconvert hex to rgb javascrithex to rgb angularrgb to hexconvert hex to rgb es6convert hex to rgb javascripthex to rgb colorsconvert hex color to rgb javascriptjs hex to rgb arrayrgb to hex conversion function in javascriptnodejs hex to rgbhexstring to rgb array jshow to change a hex code into rgb in javascripthex to rgb js function 27hextorgb 27 is not definedjavadcript hex to rgbconvert color to rgb jsconvert hex to rgba jsconvert rgb to hex in jsrgba to hex converterhex color to int javascriptcolor input convert to rgb javascriptconvert rgb to hex typescriptrgbtohex javascriptconvert hex to rgbargb to hex conversion javascriptjavascript change rgb to hexjs color to rgbrgb hex converter javascriptjavascript hex to rgbtransform hex to rgba jsconverting rgb to hex javascriptjs hex to hsl and rgbhex number to rgb jshexcolor to number javascriptrgb into hex in jsconvert hex to rgb functionconvert rgb color value to number javascripthex code to rgba javascriptrgba to hexjavascript convert rgb into hexconvert hex to rgba javascriptger rgb equivalent to string color javsctipshextorgb typescriptjs rgba to hexjavascript convert rgb to hex in a stringhexa to rgbargb to hex conversion codewars javascriptconvert rgb style value to hex value 2c javascriptvariable color rgb to hex javascriptconvert rgb to hex code in javascriptrgba to hex converter javascriptcovnert hex to rbg with javascriptrjs hex to rgbafunction rgb to hexajavascript rgb to hexaget rgb from hex jsjs convert hexcolor to rgbparse brazilian color to hexadecimal javascriptcolor rgb to hex javascriptconvert rgh to hex jscalculate rgb to hex jshex to rgb programjavascript rgb to hexrgb to hex and back javascriptconvert hex color to rgb in javascriptjs hexa to rgb convertercolor rgb to hex 220x 22rgb channels to hex jscolor hex to rgba javascriptjs from hex to rgbjs hexa to rgbajavascript convert rgb to hexjavascript from rgb to hexjavascript get rgb from hex numberjavascript convert rgb to hex getpropertyvaluehex to rgbhex to rgb typescriptjs convert hex color to rgbhow to convert rgb to hexadecimal in javascripttransform rgb to hex jstransform hexa to rgba jsrgb to hex javascript codejs to rb converterjs change hex to rgbjs get color with bit formathexa to rgb jsrgb to hex conversion jsconvert rgb color to hex javascriptjs convert hex to rgbrgba to hex in jsrgb to hex cconver rgba to hexa by javascriptjs rgb to hexget rgba to hex javascriptrgb to hexadecimal notation jsturn hex to rgb jsconvert rgb to hexjs function that convert rgba into hexget color in hex format jsjs hexa to rgbconvert rgb to hexadecimal javascripthow to convert hex to rgb in reactrgb to string javascriptconvert rgba to hex in javascriptchange hex to rgb javascriptjavascript convert rgb string to hexjs rgb to 0xrgbconvert hex to rgb jsjavascript function to convert rgb to hexhex to rgb string in jshex to rgb jasrgba to hex javacsriptjavascript hextorgbchange rgb to hexidecimals jshax to rgbjs convert rgb to hexjs add white to hexfunction to convert hex to rgbrgb hex converter javascript from htmlget rgba from hex javascriptrgb to hexjsjavascript convert hex to rgbhexadecimal color to rgbahow to convert hexadecimal color code to rgb in javascriptrgb from hexajavascript convert rgb to hex colorhex to rgb color converter javascriptrbg to hexcodes in jsconvert rgba to hex javascript codeis there a function to convert rgb to hex javascripthow to convert rgb into hex jsfunction hextorgb stackoverflowjavascript convert color string to rgbcss rgb to hex jshex code to rgb javascriptrgb to hex convertor javascriptreact convert color to hexhow to convert rgb to hexhex string to rgb javascriptjs string to rgbhex to rgb convertorrgb ot hex jsjavascript convert rgb to hexadecimaljs rgb to hexadecimalconvert hex color code to rgb javascripthex to rgb nodejsfrom hex to rgb javascriptconvert color to hex javascriptwork with rgb in javascriptrgba to hex jsjava script rgb to hexhex to rgba jsjavascript rbg to hexjs get rgb from hexrgbtohex functionrgb to hex javascript algorithmhex in rgbhow to convert rgba to hex in javascriptrgb to hex convertor in js function to convert rgb to hex jshex to rgb on javascriptjs hex color to rgbcss function convert hex to rgbpass rgb to hexjshexacimal color to rgb functionjavascript convert hex to rgbargba to hexhex javascriptchange color of an integer javascriptconvert rgb 2825 2c 0 2c 0 29 string to hex javascripthow to convert rgb to hexadecimal in javascrpttypescript convert number to hex colorget hex code from rgb jquerycovert rgb to hex jsconvert hex string to rgb javascriptrgb to hex color jshex to rgb converter javascripttypescript convert color to rgbhex color in rgbcolor hexadecimal to rgb jsjs color int to rgbhexa to rgb javascript functionrgb to hex conversioncolor convert rgb to hex 220x 22hex code to rgbhex to rgb function