parseInt() function in Javascript | HEX to RGB Color Code

This function converts the hex color value in RGB color format.

(Hex code: #00ff08) The first two letters (00) in hex code represent for red color, the middle two letters (ff) are for green color and the last two letters (08) represent for blue color.

Use parseInt() function to produce RGB value from HEX. Its first parameter contains-

  • two digit of hex code, and
  • the second parameter needs a predefined value 16 (sixteen).

Example-

<!DOCTYPE html>
<html>
<head>
  <title>HEX TO RGB</title>
</head>
<body>

<script>
		var red=parseInt("00",16);
		var green=parseInt("ff",16);
		var blue=parseInt("08",16);
		var rgb="rgb("+red+","+green+","+blue+")";
		alert(rgb);
	</script>
</body>
</html>

Leave a Comment