html5-qrcode vs jsqr vs qr-scanner vs qrcode-reader
QR Code Scanning Libraries for Web Applications
html5-qrcodejsqrqr-scannerqrcode-readerSimilar Packages:

QR Code Scanning Libraries for Web Applications

html5-qrcode, jsqr, qr-scanner, and qrcode-reader are JavaScript libraries designed to decode QR codes within web environments. html5-qrcode is a high-level solution that manages camera permissions and video streams out of the box. jsqr is a low-level engine that requires manual handling of image data, often used when custom video pipelines are needed. qr-scanner is a modern, lightweight library optimized for performance with web worker support. qrcode-reader is a legacy library that primarily handles static image data and is less maintained than modern alternatives.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
html5-qrcode06,1202.63 MB4333 years agoApache-2.0
jsqr04,007-965 years agoApache-2.0
qr-scanner02,862524 kB118-MIT
qrcode-reader0283-179 years agoApache-2.0

QR Code Scanning Libraries: Architecture and Implementation Compared

When integrating QR code scanning into a web application, the choice of library dictates how much control you have over the camera, the video stream, and the decoding process. html5-qrcode, jsqr, qr-scanner, and qrcode-reader represent different points on the spectrum from high-level abstraction to low-level control. Let's examine how they handle core engineering challenges.

πŸ“Ή Camera Access and Video Stream Handling

html5-qrcode manages the entire media stream lifecycle for you.

  • It requests camera permissions and attaches the video stream to a DOM element automatically.
  • You simply provide a container ID and a callback for success.
// html5-qrcode: High-level camera handling
const html5QrCode = new Html5Qrcode("reader");
html5QrCode.start(
  { facingMode: "environment" },
  { fps: 10, qrbox: 250 },
  (decodedText) => console.log(decodedText)
);

jsqr does not handle camera access at all.

  • You must use the native navigator.mediaDevices API to get the stream.
  • You are responsible for drawing frames to a canvas and extracting image data.
// jsqr: Manual camera setup
const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } });
videoElement.srcObject = stream;
videoElement.onplay = () => {
  const imageData = ctx.drawImage(videoElement, 0, 0, width, height);
  const code = jsQR(imageData.data, width, height);
};

qr-scanner provides a helper class to manage the video element.

  • It wraps the native API but keeps the implementation lightweight.
  • You pass the video element to the scanner instance.
// qr-scanner: Semi-automated video handling
const scanner = new QrScanner(videoElement, result => console.log(result));
scanner.start();

qrcode-reader has no built-in camera support.

  • Like jsqr, you must manually capture frames from a video stream.
  • It expects a specific image object format rather than raw canvas data.
// qrcode-reader: Manual camera setup
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
videoElement.srcObject = stream;
videoElement.onplay = () => {
  const image = { data: ctx.getImageData(0, 0, width, height) };
  qrcodeReader.decode(image);
};

πŸ–ΌοΈ Decoding Static Images vs Live Streams

html5-qrcode supports both modes via distinct methods.

  • You can switch between scanning a live camera feed and uploading a file.
  • The API remains consistent across both input types.
// html5-qrcode: File scanning
html5QrCode.scanFile(fileInput.files[0], true)
  .then(text => console.log(text));

jsqr works on raw image data arrays.

  • It does not distinguish between live or static; it only sees pixel data.
  • You must convert any image source (file or video) into a Uint8ClampedArray.
// jsqr: Raw data decoding
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const code = jsQR(imageData.data, imageData.width, imageData.height);

qr-scanner offers a static method for files and a class for streams.

  • This separation keeps the bundle size small for use cases that only need one mode.
  • The static method handles file reading internally.
// qr-scanner: Static file scanning
QrScanner.scanImage(fileInput.files[0])
  .then(result => console.log(result));

qrcode-reader is designed primarily for static image objects.

  • It requires the image data to be wrapped in a specific object structure.
  • It is less flexible when switching between input sources dynamically.
// qrcode-reader: Static image decoding
const image = { data: ctx.getImageData(0, 0, w, h) };
qrcodeReader.decode(image);

βš™οΈ Performance and Threading

html5-qrcode runs decoding on the main thread by default.

  • Heavy processing can cause UI jank during scanning.
  • Configuration options allow you to adjust the scan frequency to mitigate this.
// html5-qrcode: Configuring scan rate
html5QrCode.start(
  { facingMode: "environment" },
  { fps: 5 }, // Limit frames per second to save CPU
  onScanSuccess
);

jsqr runs entirely on the main thread.

  • Since it is a low-level library, threading is up to you.
  • You must manually offload work to a Web Worker if needed.
// jsqr: Manual worker implementation
// You must write the worker code yourself to use jsqr off-thread
worker.postMessage({ data: imageData.data, width, height });

qr-scanner supports Web Workers out of the box.

  • It can offload the heavy decoding logic to a separate thread.
  • This keeps the UI responsive even during intensive scanning tasks.
// qr-scanner: Enabling Web Worker
const scanner = new QrScanner(
  videoElement, 
  result => console.log(result),
  { highlightScanRegion: true, highlightCodeOutline: true }
);
// Worker path is configured during build or via CDN

qrcode-reader runs on the main thread.

  • Being an older library, it lacks modern concurrency features.
  • Performance depends heavily on the host application's optimization.
// qrcode-reader: Main thread execution
// No built-in worker support; runs synchronously
qrcodeReader.decode(image);

🎨 Customization and UI Control

html5-qrcode renders its own UI overlay.

  • It provides a default scan box and camera selection dropdown.
  • Customizing the look requires CSS overrides or using the raw API.
// html5-qrcode: Using raw API for custom UI
const html5QrCode = new Html5Qrcode("full-screen-region");
// You must build your own video element and overlay if not using default

jsqr provides no UI components.

  • You have full control to draw custom overlays on the canvas.
  • Ideal for branded experiences where default UI is not acceptable.
// jsqr: Custom overlay drawing
if (code) {
  ctx.beginPath();
  ctx.moveTo(code.location.topLeftCorner.x, code.location.topLeftCorner.y);
  ctx.lineTo(code.location.topRightCorner.x, code.location.topRightCorner.y);
  ctx.stroke();
}

qr-scanner allows optional highlight rendering.

  • It can draw a box around the detected code automatically.
  • You can disable this to render your own graphics.
// qr-scanner: Built-in highlights
const scanner = new QrScanner(video, result => {}, {
  highlightScanRegion: true,
  highlightCodeOutline: true
});

qrcode-reader provides no UI or drawing helpers.

  • It returns coordinates, but you must render them.
  • Requires more boilerplate code to visualize the scan area.
// qrcode-reader: Manual visualization
qrcodeReader.callback = (error, result) => {
  if (!error) {
    // Manually draw result.bounds on canvas
  }
};

πŸ› οΈ Maintenance and Ecosystem

html5-qrcode is actively maintained with frequent updates.

  • It addresses browser compatibility issues regularly.
  • Suitable for long-term projects requiring stability.
// html5-qrcode: Standard import
import { Html5Qrcode } from "html5-qrcode";

jsqr is stable but sees fewer feature updates.

  • It is a port of a C++ library, so the core logic changes rarely.
  • Good for stable, low-level integration needs.
// jsqr: Standard import
import jsQR from "jsqr";

qr-scanner is modern and actively developed.

  • It leverages modern browser APIs for better efficiency.
  • Recommended for new projects prioritizing performance.
// qr-scanner: Standard import
import QrScanner from "qr-scanner";

qrcode-reader is considered legacy with minimal recent activity.

  • It may not support newer browser features or security standards.
  • Risk of technical debt if used in new greenfield projects.
// qrcode-reader: Standard import
import QrcodeReader from "qrcode-reader";

🀝 Similarities: Shared Ground Between Libraries

Despite their architectural differences, all four libraries share the same fundamental goal and some common traits.

1. πŸ” Core Decoding Logic

  • All rely on similar underlying algorithms to detect patterns.
  • They return the decoded text string upon success.
// All libraries eventually provide the decoded text
// html5-qrcode
onScanSuccess(decodedText);
// jsqr
console.log(code.data);
// qr-scanner
result => console.log(result.data);
// qrcode-reader
callback(error, result) => console.log(result.result);

2. 🌐 Browser Compatibility

  • All run in standard web browsers without native plugins.
  • They depend on the Canvas API for image processing.
// All require canvas context for image data
const ctx = canvas.getContext("2d");
// Used by jsqr, qrcode-reader, and manually by others

3. βœ… Error Handling

  • All provide mechanisms to handle decode failures.
  • They return null or trigger error callbacks when no code is found.
// html5-qrcode
onScanFailure(error);
// jsqr
if (!code) { /* handle failure */ }
// qr-scanner
.catch(error => console.error(error));
// qrcode-reader
callback(error, result) => if (error) { /* handle */ }

4. πŸ“¦ Installation

  • All are distributed via npm for easy integration.
  • They can be bundled with Webpack, Vite, or used via CDN.
// Installation command is similar for all
npm install html5-qrcode
npm install jsqr
npm install qr-scanner
npm install qrcode-reader

πŸ“Š Summary: Key Differences

Featurehtml5-qrcodejsqrqr-scannerqrcode-reader
LevelHigh-levelLow-levelMid-levelLow-level (Legacy)
Camera Handlingβœ… Built-in❌ Manualβœ… Helper Class❌ Manual
Web Workers❌ Main Thread❌ Manualβœ… Built-in❌ Main Thread
UI Componentsβœ… Default UI❌ None⚠️ Optional Highlights❌ None
Maintenanceβœ… Active⚠️ Stableβœ… Active⚠️ Legacy

πŸ’‘ The Big Picture

html5-qrcode is the rapid deployment choice πŸš€ β€” perfect for internal tools, prototypes, or when you need a working scanner in minutes without worrying about camera permissions.

jsqr is the custom engine choice πŸ› οΈ β€” best when you are building a specialized video pipeline or need to integrate scanning into a complex canvas manipulation workflow.

qr-scanner is the modern balanced choice βš–οΈ β€” ideal for production consumer apps where performance matters and you want a lightweight solution with worker support.

qrcode-reader is the legacy choice πŸ•°οΈ β€” generally avoid for new work, but useful if you are maintaining older systems that depend on its specific API.

Final Thought: For most modern frontend applications, qr-scanner offers the best balance of performance and ease of use. However, if you need a full UI kit immediately, html5-qrcode saves significant development time.

How to Choose: html5-qrcode vs jsqr vs qr-scanner vs qrcode-reader

  • html5-qrcode:

    Choose html5-qrcode if you need a complete, plug-and-play solution that handles camera access, UI rendering, and scanning logic with minimal setup. It is ideal for rapid prototyping or applications where developer speed is more critical than bundle size optimization.

  • jsqr:

    Choose jsqr if you require full control over the image processing pipeline, such as when integrating with custom video elements or canvas manipulations. It is best suited for advanced use cases where you need to decode raw image data without built-in camera management.

  • qr-scanner:

    Choose qr-scanner if performance and bundle size are top priorities, and you want a modern library with web worker support to avoid blocking the main thread. It is suitable for production apps that need a balance between ease of use and efficiency.

  • qrcode-reader:

    Avoid qrcode-reader for new projects as it is largely considered legacy software with infrequent updates. Only consider it if you are maintaining an older codebase that already depends on its specific API for static image decoding.

README for html5-qrcode

Html5-QRCode

Lightweight & cross platform QR Code and Bar code scanning library for the web

Use this lightweight library to easily / quickly integrate QR code, bar code, and other common code scanning capabilities to your web application.

Key highlights

Supports two kinds of APIs

  • Html5QrcodeScanner β€” End-to-end scanner with UI, integrate with less than ten lines of code.

  • Html5Qrcode β€” Powerful set of APIs you can use to build your UI without worrying about camera setup, handling permissions, reading codes, etc.

Support for scanning local files on the device is a new addition and helpful for the web browser which does not support inline web-camera access in smartphones. Note: This doesn't upload files to any server β€” everything is done locally.

CircleCI GitHub issues GitHub tag (latest by date) GitHub Codacy Badge Gitter

GitHub all releases npm

Demo at scanapp.orgDemo at qrcode.minhazav.dev - Scanning different types of codes

We need your help!

image Help incentivise feature development, bug fixing by supporting the sponsorhip goals of this project. See list of sponsered feature requests here.

ko-fi

Documentation

The documentation for this project has been moved to scanapp.org/html5-qrcode-docs.

Supported platforms

We are working continuously on adding support for more and more platforms. If you find a platform or a browser where the library is not working, please feel free to file an issue. Check the demo link to test it out.

Legends

  • Means full support β€” inline webcam and file based
  • Means partial support β€” only file based, webcam in progress

PC / Mac

Firefox
Firefox
Chrome
Chrome
Safari
Safari
Opera
Opera
Edge
Edge

Android

Chrome
Chrome
Firefox
Firefox
Edge
Edge
Opera
Opera
Opera-Mini
Opera Mini
UC
UC

IOS

Safari
Safari
Chrome
Chrome
Firefox
Firefox
Edge
Edge
**

* Supported for IOS versions >= 15.1

Before version 15.1, Webkit for IOS is used by Chrome, Firefox, and other browsers in IOS and they do not have webcam permissions yet. There is an ongoing issue on fixing the support for iOS - issue/14

Framework support

The library can be easily used with several other frameworks, I have been adding examples for a few of them and would continue to add more.

Html5VueJsElectronJsReactLit

Supported Code formats

Code scanning is dependent on Zxing-js library. We will be working on top of it to add support for more types of code scanning. If you feel a certain type of code would be helpful to have, please file a feature request.

CodeExample
QR Code
AZTEC
CODE_39
CODE_93
CODE_128
ITF
EAN_13
EAN_8
PDF_417
UPC_A
UPC_E
DATA_MATRIX
MAXICODE*
RSS_14*
RSS_EXPANDED*

*Formats are not supported by our experimental integration with native BarcodeDetector API integration (Read more).

Description - View Demo

See an end to end scanner experience at scanapp.org.

This is a cross-platform JavaScript library to integrate QR code, bar codes & a few other types of code scanning capabilities to your applications running on HTML5 compatible browser.

Supports:

  • Querying camera on the device (with user permissions)
  • Rendering live camera feed, with easy to use user interface for scanning
  • Supports scanning a different kind of QR codes, bar codes and other formats
  • Supports selecting image files from the device for scanning codes

How to use

Find detailed guidelines on how to use this library on scanapp.org/html5-qrcode-docs.

Demo


Scan this image or visit blog.minhazav.dev/research/html5-qrcode.html

For more information

Check these articles on how to use this library:

Screenshots

screenshot
Figure: Screenshot from Google Chrome running on MacBook Pro

Documentation

Find the full API documentation at scanapp.org/html5-qrcode-docs/docs/apis.

Extra optional configuration in start() method

Configuration object that can be used to configure both the scanning behavior and the user interface (UI). Most of the fields have default properties that will be used unless a different value is provided. If you do not want to override anything, you can just pass in an empty object {}.

fps β€” Integer, Example = 10

A.K.A frame per second, the default value for this is 2, but it can be increased to get faster scanning. Increasing too high value could affect performance. Value >1000 will simply fail.

qrbox β€” QrDimensions or QrDimensionFunction (Optional), Example = { width: 250, height: 250 }

Use this property to limit the region of the viewfinder you want to use for scanning. The rest of the viewfinder would be shaded. For example, by passing config { qrbox : { width: 250, height: 250 } }, the screen will look like:

This can be used to set a rectangular scanning area with config like:

let config = { qrbox : { width: 400, height: 150 } }

This config also accepts a function of type

/**
  * A function that takes in the width and height of the video stream 
* and returns QrDimensions.
* 
* Viewfinder refers to the video showing camera stream.
*/
type QrDimensionFunction =
    (viewfinderWidth: number, viewfinderHeight: number) => QrDimensions;

This allows you to set dynamic QR box dimensions based on the video dimensions. See this blog article for example: Setting dynamic QR box size in Html5-qrcode - ScanApp blog

This might be desirable for bar code scanning.

If this value is not set, no shaded QR box will be rendered and the scanner will scan the entire area of video stream.

aspectRatio β€” Float, Example 1.777778 for 16:9 aspect ratio

Use this property to render the video feed in a certain aspect ratio. Passing a nonstandard aspect ratio like 100000:1 could lead to the video feed not even showing up. Ideal values can be:

ValueAspect RatioUse Case
1.3333344:3Standard camera aspect ratio
1.77777816:9Full screen, cinematic
1.01:1Square view

If you do not pass any value, the whole viewfinder would be used for scanning. Note: this value has to be smaller than the width and height of the QR code HTML element.

disableFlip β€” Boolean (Optional), default = false

By default, the scanner can scan for horizontally flipped QR Codes. This also enables scanning QR code using the front camera on mobile devices which are sometimes mirrored. This is false by default and I recommend changing this only if:

  • You are sure that the camera feed cannot be mirrored (Horizontally flipped)
  • You are facing performance issues with this enabled.

Here's an example of a normal and mirrored QR Code

Normal QR CodeMirrored QR Code

rememberLastUsedCamera β€” Boolean (Optional), default = true

If true the last camera used by the user and weather or not permission was granted would be remembered in the local storage. If the user has previously granted permissions β€” the request permission option in the UI will be skipped and the last selected camera would be launched automatically for scanning.

If true the library shall remember if the camera permissions were previously granted and what camera was last used. If the permissions is already granted for "camera", QR code scanning will automatically * start for previously used camera.

supportedScanTypes - Array<Html5QrcodeScanType> | []

This is only supported for Html5QrcodeScanner.

Default = [Html5QrcodeScanType.SCAN_TYPE_CAMERA, Html5QrcodeScanType.SCAN_TYPE_FILE]

This field can be used to:

  • Limit support to either of Camera or File based scan.
  • Change default scan type.

How to use:

function onScanSuccess(decodedText, decodedResult) {
  // handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

let config = {
  fps: 10,
  qrbox: {width: 100, height: 100},
  rememberLastUsedCamera: true,
  // Only support camera scan type.
  supportedScanTypes: [Html5QrcodeScanType.SCAN_TYPE_CAMERA]
};

let html5QrcodeScanner = new Html5QrcodeScanner(
  "reader", config, /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess);

For file based scan only choose:

supportedScanTypes: [Html5QrcodeScanType.SCAN_TYPE_FILE]

For supporting both as it is today, you can ignore this field or set as:

supportedScanTypes: [
  Html5QrcodeScanType.SCAN_TYPE_CAMERA,
  Html5QrcodeScanType.SCAN_TYPE_FILE]

To set the file based scan as defult change the order:

supportedScanTypes: [
  Html5QrcodeScanType.SCAN_TYPE_FILE,
  Html5QrcodeScanType.SCAN_TYPE_CAMERA]

showTorchButtonIfSupported - boolean | undefined

This is only supported for Html5QrcodeScanner.

If true the rendered UI will have button to turn flash on or off based on device + browser support. The value is false by default.

Scanning only specific formats

By default, both camera stream and image files are scanned against all the supported code formats. Both Html5QrcodeScanner and Html5Qrcode classes can be configured to only support a subset of supported formats. Supported formats are defined in enum Html5QrcodeSupportedFormats.

enum Html5QrcodeSupportedFormats {
  QR_CODE = 0,
  AZTEC,
  CODABAR,
  CODE_39,
  CODE_93,
  CODE_128,
  DATA_MATRIX,
  MAXICODE,
  ITF,
  EAN_13,
  EAN_8,
  PDF_417,
  RSS_14,
  RSS_EXPANDED,
  UPC_A,
  UPC_E,
  UPC_EAN_EXTENSION,
}

I recommend using this only if you need to explicitly omit support for certain formats or want to reduce the number of scans done per second for performance reasons.

Scanning only QR code with Html5Qrcode

const html5QrCode = new Html5Qrcode(
  "reader", { formatsToSupport: [ Html5QrcodeSupportedFormats.QR_CODE ] });
const qrCodeSuccessCallback = (decodedText, decodedResult) => {
    /* handle success */
};
const config = { fps: 10, qrbox: { width: 250, height: 250 } };

// If you want to prefer front camera
html5QrCode.start({ facingMode: "user" }, config, qrCodeSuccessCallback);

Scanning only QR code and UPC codes with Html5QrcodeScanner

function onScanSuccess(decodedText, decodedResult) {
  // Handle the scanned code as you like, for example:
  console.log(`Code matched = ${decodedText}`, decodedResult);
}

const formatsToSupport = [
  Html5QrcodeSupportedFormats.QR_CODE,
  Html5QrcodeSupportedFormats.UPC_A,
  Html5QrcodeSupportedFormats.UPC_E,
  Html5QrcodeSupportedFormats.UPC_EAN_EXTENSION,
];
const html5QrcodeScanner = new Html5QrcodeScanner(
  "reader",
  {
    fps: 10,
    qrbox: { width: 250, height: 250 },
    formatsToSupport: formatsToSupport
  },
  /* verbose= */ false);
html5QrcodeScanner.render(onScanSuccess);

Experimental features

The library now supports some experimental features which are supported in the library but not recommended for production usage either due to limited testing done or limited compatibility for underlying APIs used. Read more about it here. Some experimental features include:

How to modify and build

  1. Code changes should only be made to /src only.

  2. Run npm install to install all dependencies.

  3. Run npm run-script build to build JavaScript output. The output JavaScript distribution is built to /dist/html5-qrcode.min.js. If you are developing on Windows OS, run npm run-script build-windows.

  4. Testing

    • Run npm test
    • Run the tests before sending a pull request, all tests should run.
    • Please add tests for new behaviors sent in PR.
  5. Send a pull request

    • Include code changes only to ./src. Do not change ./dist manually.
    • In the pull request add a comment like
    @all-contributors please add @mebjas for this new feature or tests
    
    • For calling out your contributions, the bot will update the contributions file.
    • Code will be built & published by the author in batches.

How to contribute

You can contribute to the project in several ways:

  • File issue ticket for any observed bug or compatibility issue with the project.
  • File feature request for missing features.
  • Take open bugs or feature request and work on it and send a Pull Request.
  • Write unit tests for existing codebase (which is not covered by tests today). Help wanted on this - read more.

Support πŸ’–

This project would not be possible without all of our fantastic contributors and sponsors. If you'd like to support the maintenance and upkeep of this project you can donate via GitHub Sponsors.

Sponsor the project for priortising feature requests / bugs relevant to you. (Depends on scope of ask and bandwidth of the contributors).

webauthor@ ben-gy bujjivadu

Help incentivise feature development, bug fixing by supporting the sponsorhip goals of this project. See list of sponsered feature requests here.

Also, huge thanks to following organizations for non monitery sponsorships

Credits

The decoder used for the QR code reading is from Zxing-js https://github.com/zxing-js/library