Create Hex To RGBA Converter Tool

Today I am going to show you how to create a hex to RGBA converter using javascript. This is very easy to make this tools using jquery.
First, create a file name as hex2rgba.php and write down this code into this page.

<html lang="en" xmlns="">;
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title>hex to rgba converter</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" type="text/css" href="//" media="all,print"/>
<script src="//"></script>
<script src="hex.min.js"></script>
<meta http-equiv="X-Frame-Options" content="deny"/>
font-size: 20px;
<body align="center">
<h1>hex to rgba converter</h1>
<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="hexcolor">Hex Color</label>
<div class="input-group">
<div class="input-group-addon">#</div>
<input type="text" class="form-control" id="hexcolor" value="FFFFFF">
<div class="input-group">
<div class="input-group-addon">Opacity</div>
<input type="number" class="form-control" id="opacity" value="70">
<button type="submit" id="convert" class="btn btn-primary">Convert</button>
<div id="result"></div>

After creating this script now we have to create jquery function for this script. Already we linked js file into this script hex.min.js. Now write down some code for the hex.min.js file. Create a hex.min.js file and write down this code into this file.

$(document).ready(function() {

function hex2rgba_convert(hex,opacity){
hex = hex.replace('#','');
r = parseInt(hex.substring(0,2), 16);
g = parseInt(hex.substring(2,4), 16);
b = parseInt(hex.substring(4,6), 16);

result = 'rgba('+r+','+g+','+b+','+opacity/100+')';
return result;
var color = $('#hexcolor').val();
var opacity = $('#opacity').val();
return false;
After creating both file put hex2rga.php and hex.min.js file in same directory, then run this script into your server and open this tools into browser. Look it's ready for use.

Did you like this article? it will be appreciated if you share a coffee or burger with the author

Sent $5 to the author
Sent $10 to the author

Sajjad Hossain
Hi, I'm Sajjad Hossain, a PHP Developer working on PHP Development since 2012. If you have a project that you want to start you can contact me. I'm currently available for freelance work. Ping me on Facebook, WhatsApp or Skype.

We use cookies on our website. To find out more about how and why they are used or opt-out, please read our Cookie Policy. By choosing "I Accept", you consent to our use of cookies. Cookie Policy