showing results for - "javascript rgb to hex"
Sara
12 Jun 2016
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"
Cassie
28 Mar 2017
1function hexToRgb(hex){
2	var result = /^#?([a-f\d]{2}])([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
3  	
4 	return result ? {
5    	r: parseInt(result[1],  16);
6      	g: parseInt(result[2],  16);
7  		b: parseInt(result[3],  16);
8    } : null;
9}
10var hex = "#0a3678";
11console.log(hexToRgb(hex).r+","+hexToRgb(hex).g+","+hexToRgb(hex).b);//10,54,120
Claudio
08 Jan 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";
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 jsconvert 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 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 stringcalculate hex from rgb jsjavascript color string to rgbconvert 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 hex color to rgba javascriptconvert rgb to hex javascripthex 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 javscriptjs convert rgb to hexadecimalde hexadecimal a rgb jshextorgbarrayjs 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 javascriptconvert pantone to rgb 2bjavascriptconvert hexa to rgb javascriptjavascript hex inverterreturn rgb int from hexconvert rgb to hex javascriptpacrgb to 23 javascriptjs comvert rgb to hexjavascript convert color from hex to rgbget decimal color from hex javascriptjavascript 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 hex rgb to hex in jsjavascript convert rbg to hexhex rgb converter javascriptrgb to hex in javascriptrgb 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 rgbjavascript rpg to hexhow to combine rgb to hexa javafrom rbg 28r 2cg 2cb 29 to int jsjavascript rgb to hex codejavascript function to convert hex to rgbhow to convert color to rgb with javascriptjs rgb to hex colorrgb to hexadecimal javascriptrgb 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 javascriptsimple rgb to hex jsjavascript rgb to hexadecimalrgb to hex conversion javascriptjshex to rgbparse hex into color jsrgb string to hex in javascriptjs convert color hex code to rgbhex to rgb conversion javascriptjavascript hrx to rgbconvert rgb to hex javascript onlinejavascript convert number in rgbjavascript rgba to hexhow to convert hex into rgba in jsrgb to hex javascript functionconvert 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 javascriptrgb to hex converter javascriptconvert hex to rgbconvert rgba to hex in jshex to rgba javascripthextorgb js not foundtransform hex to rgb jsrgb para hexadecimal jsconverting rgb value to hexcodei n jsjavascript function rgb to hexfrom hexadecimal to color jsrgb to hex jaavscriptjavascript convert rgb color as hexjs hex to rgbrgb to hex function javascriptjs convert hex string into rgbfunction hex to rgb stack overflowjs rgb 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 jshow to convert 8 digit hex to rgb in javascriptcolor to hex jsjs style rgb to hexhextorgb jsjavascript color conversionrgb to hex conversion javascript codewarsconvert hex to rgb javascrithex to rgb angularrgb to hexconvert hex to rgb es6convert hex to rgb javascriptjs color conversionconvert 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 jshow to turn a hex color into rgb values in javascriptconvert hex to rgba jsconvert rgb to hex in jshex color to int javascriptcolor input convert to rgb javascriptrgbtohex javascriptrgb to hex conversion javascriptjavascript change rgb to hexcalculate rgb from hex javascriptjs 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 javascriptjavascript convert rgb into hexconvert hex to rgba javascriptger rgb equivalent to string color javsctipshextorgb typescriptjs rgba to hexjavascript convert rgb to hex in a stringrgb 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 jsjavascript 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 jsconver 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 jshex to rgb string in jsjavascript function to convert rgb to hexhex to rgb jasrgba to hex javacsriptjavascript hextorgbchange rgb to hexidecimals jshax to rgbjs convert rgb to hexjs add white to hexrgb hex converter javascript from htmlget rgba from hex javascriptrgb to hexjsjavascript convert hex to rgbhow to convert hexadecimal color code to rgb in javascriptjavascript 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 rgbrgb 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 algorithmhow 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 rgbpass rgb to hexjshexacimal color to rgb functionjavascript convert hex to rgbachange color of an integer javascriptrgba to hexhex 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 rgbjs change from hex to rgb hsl functioncolor hexadecimal to rgb jsjs color int to rgbhexa to rgb javascript functioncolor convert rgb to hex 220x 22rgba to hex javascriptjavascript rgb to hex