showing results for - "convert hex code to rgb javascript"
Lukas
24 Jul 2017
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"
Yannik
12 Jun 2019
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
Filippo
25 Oct 2017
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
queries leading to this page
javascript 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 javascripthow 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 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 reactjavascript 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 hexrgb 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 rgbfind the whole spectrum of a hex color jsjavascript rpg to hexhow to combine rgb to hexa javafrom rbg 28r 2cg 2cb 29 to int jsjavascript rgb to hex codejs 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 javascriptsimple rgb to hex jsjavascript rgb to hexadecimalrgb to hex conversion javascriptjshex 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 onlinejavascript convert number in rgbjavascript rgba to hexhow to convert hex into rgba in jsrgb to hex js codetypescript 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 convertrgb 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 hexjs go from green to red as object gets largertypescript hex to rgbhex colour to rgb jsjs convert hex into rgb and hslhex 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 hexrgb 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 rgbjavascript convert rgb to hexjavascript from rgb to hexjavascript get rgb from hex numberhex 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 javascriptconvert hex code to rgb javascript