QR code generator template

  • HTML
  • JavaScript

Turn a URL or any text into a QR code image you can download and print.

A plain HTML and JavaScript app that makes QR codes. Enter a URL or any text, pick the margin, and get a QR code image to download. There’s no framework and no build step, so it’s easy to read and change. Use it to make codes for flyers, packaging and menus, or lift the function to add codes to your own pages.

The qr code generator app running

What it does

Any URL or text
Encode links, plain text or short messages, up to 500 characters.
Download and print
Returns a PNG you can download, with a margin you choose.
No build step
Plain HTML, CSS and JavaScript: open the files and change them, nothing to compile.
Keeps your key private
The page calls a Vercel function in api/, which holds the key, checks the input and limits each visitor to 10 codes a minute.
Runs locally in one command
npm run dev serves the page and runs the api/ functions together, the same way Vercel does, with no CLI to install.

How it works

The Vercel function: it checks the value and margin, then calls QR Code Generator.

api/qr.js
import { guard, callApi, respond, fail, str } from '../lib/apiverve.js';

const MARGINS = [0, 1, 2, 4];

/** POST /api/qr { value, margin }: a PNG QR code, returned as a temporary download URL. */
export async function POST(request) {
  const blocked = guard(request);
  if (blocked) return blocked;

  const body = await request.json().catch(() => ({}));
  const value = str(body.value, 500);
  const margin = Number(body.margin ?? 0);
  if (!value) return fail('Enter a URL or text for the QR code');
  if (!MARGINS.includes(margin)) return fail(`Margin must be one of ${MARGINS.join(', ')}`);

  return respond(() => callApi('qrcodegenerator', { json: { value, margin, format: 'png' } }));
}

See the whole file on GitHub

Deploy it

  1. Get a free API key

    The free plan includes 200 credits a month, no card needed. Create your key.

  2. Deploy it

    Click Deploy to Vercel. Vercel copies the repo to your GitHub account and asks for APIVERVE_API_KEY: paste your key there.

  3. Open your app

    Vercel builds it and gives you a live URL, usually in about a minute. Every push to the repo redeploys it.

Try the QR Code Generator API — the call this template makes

Request
POSTapi.apiverve.com/v1/qrcodegenerator
Body
Verification
Format

No key required to try it. Get a key to use it in your app.

Build your own with QR Code Generator. Start with 200 free credits. One key unlocks all 300+ APIs.

Explore the catalog

300+ APIs on the same key and the same response shape.

Browse all APIs