Developing a QR code generator from HTML, CSS and Javascript is very simple and easy. Just follow these steps and develop a qr code generator.
Please save all the files with the same names with extensions as given here
Copy this HTML code and save it as "index.html" in your device.
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML and CSS to make a QR code generator </title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrious/4.0.2/qrious.min.js"></script>
<link rel="stylesheet" href="styles.css">
<script src= "script.js"> </script>
</head>
<body>
<div id="qr-form">
<h1>QR Code Generator</h1>
<input type="text" id="text-input" placeholder="Enter text" />
<br />
<button id="generateButton">Generate QR Code</button>
<br />
<canvas id="qr-code"></canvas>
<br />
<!-- download button -->
<button id="downloadButton">Download QR Code</button>
</div>
</body>
</html>
Copy this CSS code and save it as "style.css" in your device.
CSS:
body { background-color: skyblue; }
#qr-form {
text-align: center;
width: 99%;
height: auto;
background-color: #fff;
border: 3px solid #04aa6d;
border-radius: 10px;
}
#text-input {
width: 95%;
height: 30px;
border: 3px solid #04aa6d;
border-radius: 5px;
margin-bottom: 10px;
}
#qr-form button {
color: white;
background-color: #04aa6d;
border: 1px solid #04aa6d;
width: 95%;
height: 40px;
border-radius: 5px;
margin-bottom: 10px;
}
canvas {
margin-top: 20px;
border: 1px solid #ccc;
border-radius: 4px;
}
Copy this Javascript code and save it as "script.js" in your device.
CSS:
function downloadQR() {
var canvas = document.getElementById('qr-code');
var dataURL = canvas.toDataURL('image/png');
var link = document.createElement('a');
link.href = dataURL;
link.download = 'qrcode.png';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
function generateQR() {
var qrText = document.getElementById('text-input').value;
var qr = new QRious({
element: document.getElementById('qr-code'),
value: qrText,
size: 200
});
}
// Event listeners for button clicks
document.getElementById('generateButton').addEventListener('click', generateQR);
document.getElementById('downloadButton').addEventListener('click', downloadQR);
Here is a live result of all the codes given above: