These six npm packages cover the full spectrum of QR code functionality in web applications β from scanning QR codes using device cameras to generating styled QR codes for display. html5-qrcode and qr-scanner focus on camera-based scanning with different approaches to browser compatibility. jsqr and qrcode-reader are lower-level decoding libraries that work with image data. qr-code-styling and qrious handle QR code generation, with the former emphasizing visual customization and the latter focusing on lightweight canvas/SVG output. Together, they represent different architectural choices for teams building QR code features into their applications.
Building QR code features into web applications means making two key decisions: how to scan codes from camera or images, and how to generate codes for display. The six packages we're comparing split cleanly into these two categories. Let's examine how they handle real-world scenarios.
Getting camera access in the browser requires handling permissions, device selection, and video stream management. Different packages take different approaches to this complexity.
html5-qrcode provides a complete UI wrapper around camera access. You get built-in camera selection, permission handling, and a scanning viewport.
import { Html5Qrcode } from 'html5-qrcode';
const html5Qrcode = new Html5Qrcode('reader');
html5Qrcode.start(
{ facingMode: 'environment' },
{ fps: 10, qrbox: 250 },
(decodedText) => console.log(decodedText)
);
qr-scanner gives you more control but requires manual camera setup. It works with a video element you provide and focuses purely on decoding frames.
import QrScanner from 'qr-scanner';
const video = document.getElementById('video');
const scanner = new QrScanner(video, result => console.log(result.data));
await scanner.start();
jsqr doesn't handle camera access at all. You feed it image data from any source β a video frame, uploaded image, or canvas.
import jsQR from 'jsqr';
const imageData = ctx.getImageData(0, 0, width, height);
const code = jsQR(imageData.data, width, height);
if (code) console.log(code.data);
qrcode-reader works similarly to jsqr but with an older callback-based API. You pass image data and get results through a callback.
import QrCode from 'qrcode-reader';
const qr = new QrCode();
qr.callback = (err, value) => {
if (!err) console.log(value.result);
};
qr.decode(imageData);
qr-code-styling and qrious don't scan at all β they only generate QR codes for display.
When generating QR codes, you need to decide between basic functionality and visual customization. This is where the generation libraries diverge significantly.
qr-code-styling excels at branded, customized QR codes. You can change dot patterns, add logos, apply gradients, and adjust corners.
import QRCodeStyling from 'qr-code-styling';
const qrCode = new QRCodeStyling({
data: 'https://example.com',
dotsOptions: { color: '#4267b2', type: 'rounded' },
image: '/logo.png',
imageOptions: { imageSize: 0.4 }
});
qrCode.append(document.getElementById('canvas'));
qrious focuses on simplicity. You get canvas or SVG output with basic color and size options, but no advanced styling.
import QRious from 'qrious';
const qr = new QRious({
element: document.getElementById('canvas'),
value: 'https://example.com',
size: 200,
foreground: '#000000'
});
The other four packages (html5-qrcode, jsqr, qr-scanner, qrcode-reader) don't generate QR codes β they only read them.
Bundle size and runtime performance matter differently depending on your use case. Scanning libraries need to process video frames quickly, while generation libraries run once per QR code created.
jsqr has no dependencies and minimal bundle impact. It's pure JavaScript with no external requirements.
// jsqr: Zero dependencies
import jsQR from 'jsqr';
// Bundle: ~15KB minified
qr-scanner uses Web Workers for decoding, keeping the main thread free during scanning.
// qr-scanner: Web Worker support
import QrScanner from 'qr-scanner';
QrScanner.WORKER_PATH = '/qr-scanner-worker.min.js';
html5-qrcode includes UI components and camera handling, resulting in a larger bundle but less custom code.
// html5-qrcode: Full-featured with UI
import { Html5QrcodeScanner } from 'html5-qrcode';
const scanner = new Html5QrcodeScanner();
qr-code-styling includes canvas manipulation and image processing for customization features.
// qr-code-styling: Advanced rendering
import QRCodeStyling from 'qr-code-styling';
// More bundle weight for styling features
qrious stays lightweight with basic canvas/SVG rendering.
// qrious: Minimal generator
import QRious from 'qrious';
// Small bundle for basic generation
qrcode-reader is older and hasn't received modern optimizations. It works but lacks performance improvements found in newer libraries.
// qrcode-reader: Legacy library
import QrCode from 'qrcode-reader';
// Consider newer alternatives for new projects
QR code scanning fails often β poor lighting, damaged codes, or camera issues. How each library handles these situations affects user experience.
html5-qrcode provides built-in error callbacks and UI feedback for scanning failures.
html5Qrcode.start(
config,
{ fps: 10, qrbox: 250 },
(text) => console.log('Success:', text),
(error) => console.warn('Scan error:', error)
);
qr-scanner throws errors you need to catch manually, giving you full control over error UI.
try {
await scanner.start();
} catch (error) {
console.error('Camera access failed:', error);
}
jsqr returns null when no QR code is found β no exceptions, just check the result.
const code = jsQR(imageData.data, width, height);
if (!code) {
// No QR code detected, continue scanning
}
qrcode-reader uses callbacks for both success and error cases.
qr.callback = (err, value) => {
if (err) console.error('Decode failed:', err);
else console.log('Result:', value.result);
};
qr-code-styling and qrious throw errors on invalid data, which you should wrap in try-catch blocks.
try {
const qr = new QRious({ value: 'https://example.com' });
} catch (error) {
console.error('Invalid QR data:', error);
}
Not all libraries work equally well across browsers. Camera APIs and canvas features have varying support.
html5-qrcode targets broad compatibility including older browsers. It includes fallbacks for devices without full MediaStream support.
// html5-qrcode: Broad browser support
// Works on iOS Safari, Android Chrome, desktop browsers
const scanner = new Html5Qrcode('reader');
qr-scanner requires modern browsers with full MediaStream and Web Worker support.
// qr-scanner: Modern browsers only
// iOS 11+, Chrome 53+, Firefox 55+
const scanner = new QrScanner(video, resultHandler);
jsqr works anywhere JavaScript runs since it only processes image data.
// jsqr: Universal compatibility
// No browser APIs required - pure JS
const code = jsQR(data, width, height);
qrcode-reader has similar universal compatibility but hasn't been tested against newer browser versions.
// qrcode-reader: Legacy compatibility
// Works broadly but unmaintained
qr.decode(imageData);
qr-code-styling and qrious work in any browser with canvas support, which is nearly universal today.
// Both: Canvas-based generation
// Works in all modern browsers
const qr = new QRious({ element: canvas });
Library maintenance affects long-term project health. Some packages in this comparison are no longer actively developed.
html5-qrcode is actively maintained with regular updates and issue responses. Safe for new projects.
qr-scanner is actively maintained with recent releases and modern API patterns. Good choice for greenfield development.
jsqr receives occasional updates but is relatively stable. The core decoding logic doesn't change often.
qr-code-styling is actively maintained with new styling features added regularly.
qrious is stable but sees infrequent updates. The simple feature set means fewer changes are needed.
qrcode-reader is no longer actively maintained. Avoid for new projects β use jsqr or qr-scanner instead.
| Package | Primary Use | Camera Built-in | Styling Options | Maintenance |
|---|---|---|---|---|
html5-qrcode | Scanning | β Yes | N/A | β Active |
qr-scanner | Scanning | β No | N/A | β Active |
jsqr | Scanning | β No | N/A | β οΈ Stable |
qrcode-reader | Scanning | β No | N/A | β Inactive |
qr-code-styling | Generation | N/A | β Advanced | β Active |
qrious | Generation | N/A | β οΈ Basic | β οΈ Stable |
For scanning QR codes, you have three viable options today:
html5-qrcode β Best for teams that want everything handled. You get camera UI, permissions, and scanning in one package. Ideal for customer-facing apps where reliability matters more than bundle size.
qr-scanner β Best for teams that want control. You manage the camera UI but get fast, modern decoding with Web Worker support. Ideal for apps where you already have video handling infrastructure.
jsqr β Best for specialized cases. Use it when you're processing static images or already have a custom video pipeline. Avoid it if you need camera handling.
For generating QR codes, you have two clear choices:
qr-code-styling β Best when appearance matters. Marketing materials, branded apps, or any scenario where the QR code needs to match your design system.
qrious β Best for functional needs. Admin panels, internal tools, or any scenario where the QR code just needs to work without visual flair.
Avoid qrcode-reader for new projects. It's served its purpose but lacks modern optimizations and active maintenance.
Final Thought: Most production apps will combine one scanning library with one generation library. A common pattern is html5-qrcode for scanning paired with qrious for basic generation, or qr-scanner with qr-code-styling for apps that need both performance and branded QR codes.
Choose jsqr if you need a lightweight, dependency-free decoder that works with raw image data. It's perfect for scenarios where you already have image frames from another source (like a video stream you're managing yourself) and just need decoding logic. Avoid it if you want built-in camera handling β you'll need to wire that up separately.
Choose html5-qrcode if you need a full-featured scanning solution with built-in camera handling, UI controls, and broad browser support. It's ideal for production apps where you want minimal setup and don't mind a larger bundle. The library handles permissions, camera selection, and scanning state management out of the box, making it the safest choice for teams that want reliability over minimalism.
Choose qr-code-styling if visual customization is your priority β you need branded QR codes with custom colors, logos, gradients, or dot patterns. It's the best option for marketing materials, customer-facing apps, or any scenario where the QR code's appearance matters. The trade-off is a larger bundle and more complex API than basic generators.
Choose qr-scanner if you want a modern, lightweight scanner with good performance and Web Worker support. It's ideal for teams that value bundle size and are comfortable managing camera access themselves. The library is actively maintained and uses newer browser APIs, making it a solid choice for greenfield projects targeting modern browsers.
Choose qrious if you need a simple, lightweight QR code generator with canvas and SVG support. It's perfect for internal tools, admin panels, or any scenario where basic QR generation is needed without visual customization. The API is straightforward and the bundle is small, but don't expect advanced styling features.
Avoid qrcode-reader for new projects β it's no longer actively maintained and lacks modern browser optimizations. Only consider it if you're maintaining legacy code that already depends on it. For any new scanning feature, evaluate html5-qrcode or qr-scanner instead, as they offer better performance and ongoing support.
A pure javascript QR code reading library. This library takes in raw images and will locate, extract and parse any QR code found within.
Available on npm. Can be used in a Node.js program or with a module bundler such as Webpack or Browserify.
npm install jsqr --save
// ES6 import
import jsQR from "jsqr";
// CommonJS require
const jsQR = require("jsqr");
jsQR(...);
Alternatively for frontend use jsQR.js can be included with a script tag
<script src="jsQR.js"></script>
<script>
jsQR(...);
</script>
jsQR is designed to be a completely standalone library for scanning QR codes. By design it does not include any platform specific code. This allows it to just as easily scan a frontend webcam stream, a user uploaded image, or be used as part of a backend Node.js process.
If you want to use jsQR to scan a webcam stream you'll need to extract the ImageData from the video stream. This can then be passed to jsQR. The jsQR demo contains a barebones implementation of webcam scanning that can be used as a starting point and customized for your needs. For more advanced questions you can refer to the getUserMedia docs or the fairly comprehensive webRTC sample code, both of which are great resources for consuming a webcam stream.
jsQR exports a method that takes in 3 arguments representing the image data you wish to decode. Additionally can take an options object to further configure scanning behavior.
const code = jsQR(imageData, width, height, options?);
if (code) {
console.log("Found QR code", code);
}
imageData - An Uint8ClampedArray of RGBA pixel values in the form [r0, g0, b0, a0, r1, g1, b1, a1, ...].
As such the length of this array should be 4 * width * height.
This data is in the same form as the ImageData interface, and it's also commonly returned by node modules for reading images.width - The width of the image you wish to decode.height - The height of the image you wish to decode.options (optional) - Additional options.
inversionAttempts - (attemptBoth (default), dontInvert, onlyInvert, or invertFirst) - Should jsQR attempt to invert the image to find QR codes with white modules on black backgrounds instead of the black modules on white background. This option defaults to attemptBoth for backwards compatibility but causes a ~50% performance hit, and will probably be default to dontInvert in future versions.If a QR is able to be decoded the library will return an object with the following keys.
binaryData - Uint8ClampedArray - The raw bytes of the QR code.data - The string version of the QR code data.chunks - The QR chunks.version - The QR version.location - An object with keys describing key points of the QR code. Each key is a point of the form {x: number, y: number}.
Has points for the following locations.
topRightCorner/topLeftCorner/bottomRightCorner/bottomLeftCorner;topRightFinderPattern/topLeftFinderPattern/bottomLeftFinderPatternbottomRightAlignmentPattern assuming one exists and can be located.Because the library is written in typescript you can also view the type definitions to understand the API.
jsQR is written using typescript.
You can view the development source in the src directory.
Tests can be run with
npm test
Besides unit tests the test suite contains several hundred images that can be found in the /tests/end-to-end/ folder.
Not all the images can be read. In general changes should hope to increase the number of images that read. However due to the nature of computer vision some changes may cause images that pass to start to fail and visa versa. To update the expected outcomes run npm run-script generate-test-data. These outcomes can be evaluated in the context of a PR to determine if a change improves or harms the overall ability of the library to read QR codes. A summary of which are passing
and failing can be found at /tests/end-to-end/report.json
After testing any changes, you can compile the production version by running
npm run-script build
Pull requests are welcome! Please create seperate branches for seperate features/patches.