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.

Search on PHPAns
Subscribe to PHPAns
Join with our 32000+ subscribers and get our latest articles in your email inbox for free.
Delivered by FeedBurner
We always respect your privacy and take protecting it seriously.
Connect Social With PHPAns