Open In App
Related Articles

QR Code Generator using HTML, CSS and jQuery

Like Article
Save Article
Report issue

In this article, we will learn how to build a QR generator using HTML, CSS, and jQuery. A QR code generator is an application that stores any required textual data into a QR code which can be later scanned with a QR code scanner to reveal the stored information. This code generator consists of an input field and a button which are respectively used to take the input text and convert the entered text into a QR code.

Preview Image



  • Create a folder with project name and a HTML file with any name to structure the web page using tags like div, input, img, button tag etc.
  • Now, use the class and ID CSS selectors to select the elements and style them using the CSS properties.
  • Use jQuery to get the input text and generate the QR code for the entered text onclick to the button using the click event.
  • To generate the QR code, we will use the Google Charts API. Using jQuery, the QR code image to be displayed is updated according to the image returned by the API. The API endpoint that would be used is given below.

Example: The below example explain how you can build a QR code generator using HTML, CSS and jQuery.


<!DOCTYPE html>
  <!-- Include Bootstrap for styling -->
  <link rel="stylesheet" href=
    .qr-code {
      max-width: 200px;
      margin: 10px;
  <title>QR Code Generator</title>
  <div class="container-fluid">
    <div class="text-center">
      <!-- Get a Placeholder image initially,
       this will change according to the
       data entered later -->
      <img src=
        class="qr-code img-thumbnail img-responsive" />
    <div class="form-horizontal">
      <div class="form-group">
        <label class="control-label col-sm-2"
        <div class="col-sm-10">
          <!-- Input box to enter the
              required data -->
          <input type="text" size="60"
            maxlength="60" class="form-control"
            id="content" placeholder="Enter content" />
      <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
          <!-- Button to generate QR Code for
           the entered data -->
          <button type="button" class=
            "btn btn-default" id="generate">
  <script src=
    // Function to HTML encode the text
    // This creates a new hidden element,
    // inserts the given text into it
    // and outputs it out as HTML
    function htmlEncode(value) {
      return $('<div/>').text(value)
    $(function () {
      // Specify an onclick function
      // for the generate button
      $('#generate').click(function () {
        // Generate the link that would be
        // used to generate the QR Code
        // with the given data
        let finalURL =
          htmlEncode($('#content').val()) +
        // Replace the src of the image with
        // the QR code image
        $('.qr-code').attr('src', finalURL);



jQuery is an open source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous with it’s philosophy of “Write less, do more”. You can learn jQuery from the ground up by following this jQuery Tutorial and jQuery Examples.

Last Updated : 14 Dec, 2023
Like Article
Save Article
Share your thoughts in the comments
Similar Reads