Home / AI in the Browser / QR and Barcode Scanner

QR and Barcode Scanner in JavaScript, Free with Live Demo

Free QR code and barcode scanner in plain JavaScript. Scan with your camera or a photo, read QR, EAN, UPC and more, and make your own QR codes. Works on phones.

Open live demoDownload HTML fileView code on GitHub
QR and Barcode Scanner JavaScript project: scan QR codes and barcodes with your camera

Runs on: Your device. Native: Chrome and Edge on Android and macOS, Samsung Internet. Fallback: every modern browser. Camera needs HTTPS or localhost.

What is the QR and Barcode Scanner?

Point your phone or laptop camera at a QR code or a product barcode and this page reads it instantly, drawing a box around the code it found. You can also upload a screenshot or photo, and there is a small QR maker so you can test it.

It uses the BarcodeDetector API, which is built into Chrome on Android and some other browsers. Where it is missing, the page loads a small WebAssembly version of the ZXing scanner that works the same way.

Good for

  • Event check in and ticket scanning
  • Stock and inventory apps
  • Menu, payment and link QR codes
  • Learning camera access in JavaScript

What this project does

How it works

  1. Pick a detectorThe page uses the browser's own BarcodeDetector when it exists, otherwise it loads the same API backed by ZXing WebAssembly.
  2. Scan framesAbout five times a second, the current camera frame is passed to detect(), which returns each code with its corner points.
  3. Show resultsCorners are drawn on a canvas over the video, and new codes are added to the history with a short beep.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

// Native API, or the same API backed by ZXing WebAssembly
const Detector = "BarcodeDetector" in window
  ? window.BarcodeDetector
  : (await import("https://cdn.jsdelivr.net/npm/barcode-detector@3.2.2/dist/es/ponyfill.js")).BarcodeDetector;

const detector = new Detector({ formats: ["qr_code", "ean_13", "code_128"] });

// Works with <video>, <img>, <canvas>, ImageBitmap or a Blob
const codes = await detector.detect(videoElement);
for (const c of codes) console.log(c.format, c.rawValue, c.cornerPoints);

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

How do I scan a QR code with JavaScript?

Get the camera with getUserMedia, show it in a video element, and pass frames to BarcodeDetector.detect(). This project shows the full loop with a fallback for browsers that lack the API.

Which barcode types can it read?

QR, EAN 13, EAN 8, UPC A, UPC E, Code 128, Code 39, Data Matrix, PDF417, Aztec and more, depending on the browser.

Why does the camera not start?

Browsers only allow the camera on HTTPS or localhost. On GitHub Pages it works, but opening the file straight from your disk will block it.

More AI in the Browser projects