How To Generate QR Code Using Javascript

  Jul 2023
  Category: jQuery
How To Generate QR Code Using Javascript

Hi Developers ,

Lets see How To Generate QR Code Using Javascript. To create QR Code using javascript we are using the third party API for creating the QR Code.
    The QR Code is generated based on the text given in the input field when the text is given in the input field . It collects the value from the input field and send API request along with the data.
And then recieves the response data from the API and the stores the data in the image tag to display the QR Code .

Lets Start Coding

Send a GET request of following form to our system to get a QR code graphic as PNG image (=to generate a QR code):


create-qr-code is command and data = pass text as per requirement, size = 100*100 for example.

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>How To Generate QR Code Using Javascript - ItSolutionsGuides</title>   
    <script src=""></script> 
<style type="text/css" media="screen">
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: Quicksand;
body {
    width: 100%;
    height: 100vh;
    background:linear-gradient(to right top,#b597f6,#439cfb);
    display: flex;
    justify-content: center;
    align-items: center;
.main {
    width: 50%;
    height: 70%;
    padding: 50px 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    background: #fff;
    box-shadow: 0 10px 25px -10px rgba(0,0,0,0.5);
    border-radius: 5px;
.main p {
.main .input {
    width: 90%;
    padding: 10px 25px;
    border: 3px solid #9e9e9e;
    outline: none;
    margin: 15px 0 40px;
.main .input:focus {
    border: 3px solid #439cfb;
.btn ,.input {
    border-radius: 5px;
.main .btn {
    width: 90%;
    padding: 12px 0;
    outline: none;
    border-radius: 5px;
    background: #439cfb;
    color: #fff;
    transition: 0.3s;
    margin: 0 0 25px 0;
.main .code {
    margin: 25px 0;
.main .btn:hover {
    box-shadow: 0 10px 25px -10px #439cfb;
.main #note {
    font-size: 1.2rem;
    font-family: 'Courier New', Courier, monospace;
#toast {
    position: absolute;
    bottom: 0;
    border-radius: 5px;
    padding: 15px 50px;
    background: #07f49e;
    opacity: 0;
    visibility: hidden;
    box-shadow: 0 10px 25px -10px #07f49e;
    transition: 0.3s;
} {
    visibility: visible;
    opacity: 1;
    bottom: 50px;
    <div class="main">
        <p>How To Generate QR Code Using Javascript - ItSolutionsGuides</p>
        <input type="text" class="input" value="" id="textvalue">
        <button class="btn">Generate</button>
        <img src="images/default.png" alt="Your QR Code will be show here..." class="code">
        <p id="note">Tutorial by ItSolutionsGuides</p>
    <div id="toast">Successfully Generated</div>    
var btn = document.querySelector('.btn');
var code = document.querySelector('.code');
var toast = document.querySelector('#toast');
function generate() {    
    var data = $('#textvalue').val();    
    var url = `${data}`;
    code.src = url;
function toastDiv() {
    toast.className = "show";
    setTimeout( function() {
        toast.className = toast.className.replace("show" , "");

We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.

Subscribe for NewsLetter

Be the first to know about releases and tutorial news and solutions.

We care about your data in our privacy policy.


ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.

Contact US

ITSolutionsGuides, provide users with an easy-to-use form to reach out for support or inquiries.

whatsapp  gmail  instagram-new--v1  facebook-circled  twitter-circled  linkedin  github  pinterest 

Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides