\n \n\n\n
\n

My Personal QR Generator

\n \n
\n \n \n \n \n \n \n \n
\n \n
\n \n \n
\n\n \n\n","@type":"BlogPosting","author":{"image":{"width":500,"@type":"ImageObject","height":500,"url":"https://i.ibb.co/BtbHFzW/307ce493-b254-4b2d-8ba4-d12c080d6651.jpg"},"@type":"Person","name":"ttimesnow","url":"https://www.ttimesnow.com/author/11","sameAs":["https://www.facebook.com/share/1BHcqrk1HF/?mibextid=wwXIfr"]},"description":"Learn how to build your own QR code generator from scratch using HTML, CSS, and JavaScript. Customize colors, size, and error correction—full code included!","inLanguage":"en","dateModified":"2025-07-06T00:29:07.495Z","isAccessibleForFree":true,"mainEntityOfPage":{"name":"How to Create a QR Code Generator – Easy HTML, CSS & JavaScript Tutorial","@id":"https://www.ttimesnow.com/blog/how-to-create-a-qr-code-generator-easy-html-css-javascript-tutorial","@type":"WebPage","url":"https://www.ttimesnow.com/blog/how-to-create-a-qr-code-generator-easy-html-css-javascript-tutorial"},"url":"https://www.ttimesnow.com/blog/how-to-create-a-qr-code-generator-easy-html-css-javascript-tutorial","datePublished":"2025-07-05T23:58:35.478Z","potentialAction":{"@type":"CommentAction","name":"Comment","target":"https://www.ttimesnow.com/blog/how-to-create-a-qr-code-generator-easy-html-css-javascript-tutorial#comments"},"name":"How to Create a QR Code Generator – Easy HTML, CSS & JavaScript Tutorial","publisher":{"name":"Ttimesnow","@type":"Organization","logo":{"width":180,"@type":"ImageObject","height":180,"url":"https://www.ttimesnow.com/apple-touch-icon.png"},"url":"https://www.ttimesnow.com","@id":"https://www.ttimesnow.com#organization"},"@id":"https://www.ttimesnow.com/blog/how-to-create-a-qr-code-generator-easy-html-css-javascript-tutorial#blog","headline":"How to Create a QR Code Generator – Easy HTML, CSS & JavaScript Tutorial","articleSection":"blog"}],"@context":"https://schema.org"}

How to Create a QR Code Generator – Easy HTML, CSS & JavaScript Tutorial

🔥 Read with Full Features on Our Website

Learn how to build your own QR code generator from scratch using HTML, CSS, and JavaScript. Customize colors, size, and error correction—full code included!

Published on 05 Jul 2025
By ttimesnow

Live

🔥 Read with Full Features on Our Website

 

🔗  Live Preview
Google Advertisement

Iframe

Code : 

The Bare Bones Structure

<div class="generator-container">
    <h1>My Personal QR Generator</h1>
    
    <div class="controls">
        <label>
            QR Content:
            <input type="text" id="qr-content" value="https://my-website.com">
        </label>
        
        <!-- More controls coming soon! -->
    </div>
    
    <div id="qr-display">
        <!-- The magic will appear here -->
    </div>
    
    <button id="download-btn">Save QR Code</button>
</div>
Google Advertisement

Script

// First, make sure the library is loaded
const QRCode = window.QRCode;

document.addEventListener('DOMContentLoaded', () => {
    const qrContent = document.getElementById('qr-content');
    const qrDisplay = document.getElementById('qr-display');
    
    function generateQR() {
        const text = qrContent.value.trim();
        
        if (!text) {
            qrDisplay.innerHTML = '<p>Type something first!</p>';
            return;
        }
        
        qrDisplay.innerHTML = ''; // Clear previous QR
        
        new QRCode(qrDisplay, {
            text: text,
            width: 200,
            height: 200,
            colorDark: "#000000",
            colorLight: "#ffffff",
            correctLevel: QRCode.CorrectLevel.H
        });
    }
    
    // Generate immediately
    generateQR();
    
    // Update when typing
    qrContent.addEventListener('input', generateQR);
});

The basic version worked, but I wanted to make it mine. Here's what I added:

  1. Size Control
    Because sometimes you need a tiny QR code and sometimes you need a billboard-sized one.

  2. Google Advertisement

    Color Options
    Default black-and-white is boring. I wanted neon pink if I felt like it.

<div class="controls">
    <!-- Previous input remains -->
    
    <label>
        Size: 
        <input type="range" id="qr-size" min="100" max="500" value="200">
    </label>
    
    <label>
        Color: 
        <input type="color" id="qr-color" value="#000000">
    </label>
    
    <label>
        Error Correction:
        <select id="qr-error-level">
            <option value="L">Low (7%)</option>
            <option value="M">Medium (15%)</option>
            <option value="Q">Quartile (25%)</option>
            <option value="H" selected>High (30%)</option>
        </select>
    </label>
</div>

The JavaScript updates:

const sizeInput = document.getElementById('qr-size');
const colorInput = document.getElementById('qr-color');
const errorLevelInput = document.getElementById('qr-error-level');

// Update the generateQR function
function generateQR() {
    // ... previous code ...
    
    new QRCode(qrDisplay, {
        text: text,
        width: sizeInput.value,
        height: sizeInput.value,
        colorDark: colorInput.value,
        colorLight: "#ffffff", // Keeping background white for now
        correctLevel: QRCode.CorrectLevel[errorLevelInput.value]
    });
}

// Add event listeners
sizeInput.addEventListener('input', generateQR);
colorInput.addEventListener('input', generateQR);
errorLevelInput.addEventListener('change', generateQR);

✅ Complete code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My QR Generator</title>
    <script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.1/build/qrcode.min.js"></script>
    <style>
        body {
            font-family: 'Segoe UI', sans-serif;
            background: #f5f5f5;
            padding: 20px;
        }
        .generator-container {
            max-width: 500px;
            margin: 0 auto;
            padding: 25px;
            background: white;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
            margin-bottom: 25px;
        }
        .controls {
            display: grid;
            gap: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: 500;
        }
        input, select {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        #qr-display {
            min-height: 250px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 20px 0;
            border: 2px dashed #eee;
            padding: 10px;
        }
        #download-btn {
            width: 100%;
            padding: 10px;
            background: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background 0.3s;
        }
        #download-btn:hover {
            background: #45a049;
        }
    </style>
</head>
<body>
    <div class="generator-container">
        <h1>My Personal QR Generator</h1>
        
        <div class="controls">
            <label>
                QR Content:
                <input type="text" id="qr-content" value="https://my-website.com">
            </label>
            
            <label>
                Size: 
                <input type="range" id="qr-size" min="100" max="500" value="200">
            </label>
            
            <label>
                Color: 
                <input type="color" id="qr-color" value="#000000">
            </label>
            
            <label>
                Error Correction:
                <select id="qr-error-level">
                    <option value="L">Low (7%)</option>
                    <option value="M">Medium (15%)</option>
                    <option value="Q">Quartile (25%)</option>
                    <option value="H" selected>High (30%)</option>
                </select>
            </label>
        </div>
        
        <div id="qr-display"></div>
        
        <button id="download-btn">Save QR Code</button>
    </div>

    <script>
        const QRCode = window.QRCode;
        
        document.addEventListener('DOMContentLoaded', () => {
            const qrContent = document.getElementById('qr-content');
            const qrDisplay = document.getElementById('qr-display');
            const downloadBtn = document.getElementById('download-btn');
            const sizeInput = document.getElementById('qr-size');
            const colorInput = document.getElementById('qr-color');
            const errorLevelInput = document.getElementById('qr-error-level');
            
            function generateQR() {
                const text = qrContent.value.trim();
                
                if (!text) {
                    qrDisplay.innerHTML = '<p>Please enter some text first</p>';
                    return;
                }
                
                qrDisplay.innerHTML = '';
                
                new QRCode(qrDisplay, {
                    text: text,
                    width: sizeInput.value,
                    height: sizeInput.value,
                    colorDark: colorInput.value,
                    colorLight: "#ffffff",
                    correctLevel: QRCode.CorrectLevel[errorLevelInput.value]
                });
            }
            
            // Download functionality
            downloadBtn.addEventListener('click', () => {
                const canvas = qrDisplay.querySelector('canvas');
                if (!canvas) return;
                
                const link = document.createElement('a');
                link.download = 'my-qr-code.png';
                link.href = canvas.toDataURL();
                link.click();
            });
            
            // Initial generation
            generateQR();
            
            // Update on changes
            qrContent.addEventListener('input', generateQR);
            sizeInput.addEventListener('input', generateQR);
            colorInput.addEventListener('input', generateQR);
            errorLevelInput.addEventListener('change', generateQR);
        });
    </script>
</body>
</html>

 

👉 View Full Version on Main Website ↗
👉 Read Full Article on Website