qrcode.react vs react-qr-code vs qr.js vs qr-code-styling vs qrious
Choosing QR-code encoding and rendering tools
qrcode.reactreact-qr-codeqr.jsqr-code-stylingqriousSimilar Packages:

Choosing QR-code encoding and rendering tools

Compare a raw module-matrix encoder with React SVG/Canvas components, an imperative Canvas renderer, and a styled QR object workflow.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
qrcode.react14,992,5894,296115 kB442 years agoISC
react-qr-code4,076,62089519.9 kB85 months agoMIT
qr.js2,518,699---14 years agoMIT
qr-code-styling1,228,0732,987516 kB1172 years agoMIT
qrious91,8831,616-449 years agoGPL-3.0

Encoding, output, and scanning are separate tasks

All five packages generate QR content, but at different abstraction levels. None should be chosen as a camera scanner or a decoder for an existing image. First decide whether the application needs module data, a React component, a Canvas instance, or a styled export workflow.

Raw modules and an application-owned renderer

qr.js encodes text into a modules matrix. The application decides how to draw or write that grid. It does not supply a complete image export or UI workflow merely because encoding succeeds.

Its top-level wrapper uses a truthy fallback for the correction setting. The enum value for medium correction is zero, so passing that value falls back to high correction instead of selecting medium. Account for that concrete interface limitation rather than copying an option name from another generator. The raw matrix still needs correct layout and surrounding margin in the eventual rendering.

React components

qrcode.react exposes named QRCodeSVG and QRCodeCanvas components. The encoded value can be a string or an array of text segments. Rendering size is measured in pixels, while marginSize is measured in modules and defaults to zero. Arrange the intended quiet margin deliberately rather than assuming the component already includes it.

Correction boosting can choose a higher correction level without enlarging the module-grid dimensions, so the requested level is not necessarily the final selected level. Image settings have their own size and placement contract; an overlay does not guarantee that every resulting code remains readable.

react-qr-code supplies an SVG-focused component. Its integration uses TextEncoder for string encoding, which must exist in the rendering environment. React Native needs the documented native SVG integration rather than treating a browser SVG element as a native component. Its surrounding light margin is arranged by the caller. It does not expose the same SVG/Canvas component pair as qrcode.react.

Imperative and styled rendering

qrious manages a Canvas-oriented QR instance. The application can change individual options or use set for a coordinated update. Its browser route expects DOM and Canvas facilities; a Node import does not supply those objects automatically. Its image/data-URL output belongs to rendering the code, not reading one from a camera.

qr-code-styling adds visual choices such as dot shapes, colors, and image placement, with an object that can be appended, updated, and exported. Raw-data and download operations are asynchronous. Browser and Node integration have different environment requirements, and raw-data results can be browser Blob or Node Buffer depending on the setup. Installing the package does not by itself provide every Canvas or DOM dependency.

Choose the output the product actually needs

For a React page, start with the required SVG or Canvas component and its host requirements. For a custom renderer, compare the matrix interface and its encoding limitations. For branded exports, evaluate the styling workflow and actual generated output.

Check representative payloads, languages, sizes, margins, and reading conditions. Capacity depends on encoded bytes and correction settings, so one universal character limit is misleading. A decorative design or an error-correction label alone is not proof that the final printed or displayed result works for the intended reader.

How to Choose: qrcode.react vs react-qr-code vs qr.js vs qr-code-styling vs qrious

  • qrcode.react:

    Choose this for React rendering through named SVG or Canvas components, with explicit module margins, correction, and image options.

  • react-qr-code:

    Choose this for a focused React SVG generator, with the documented separate SVG integration when targeting React Native.

  • qr.js:

    Choose this when the application intentionally owns rendering from a QR module matrix and can account for its correction-option wrapper limitation.

  • qr-code-styling:

    Choose this for configurable dot shapes, images, and styled SVG/Canvas output with an object update/export workflow.

  • qrious:

    Choose this for an imperative Canvas-oriented QR instance with options that can be updated outside a React-specific component model.

README for qrcode.react

qrcode.react

A React component to generate QR codes for rendering to the DOM.

Installation

npm install qrcode.react

Usage

qrcode.react exports two components, supporting rendering as SVG or Canvas. SVG is generally recommended as it is more flexible, but Canvas may be preferable.

All examples are shown using modern JavaScript modules and syntax. CommonJS require('qrcode.react') is also supported.

QRCodeSVG

import ReactDOM from 'react-dom';
import {QRCodeSVG} from 'qrcode.react';

ReactDOM.render(
  <QRCodeSVG value="https://reactjs.org/" />,
  document.getElementById('mountNode')
);

QRCodeCanvas

import ReactDOM from 'react-dom';
import {QRCodeCanvas} from 'qrcode.react';

ReactDOM.render(
  <QRCodeCanvas value="https://reactjs.org/" />,
  document.getElementById('mountNode')
);

Available Props

Below is a condensed type definition of the props QRCodeSVG and QRCodeCanvas accept.

type QRProps = {
  /**
   * The value to encode into the QR Code. An array of strings can be passed in
   * to represent multiple segments to further optimize the QR Code.
   */
  value: string | string[];
  /**
   * The size, in pixels, to render the QR Code.
   * @defaultValue 128
   */
  size?: number;
  /**
   * The Error Correction Level to use.
   * @see https://www.qrcode.com/en/about/error_correction.html
   * @defaultValue L
   */
  level?: 'L' | 'M' | 'Q' | 'H';
  /**
   * The background color used to render the QR Code.
   * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
   * @defaultValue #FFFFFF
   */
  bgColor?: string;
  /**
   * The foregtound color used to render the QR Code.
   * @see https://developer.mozilla.org/en-US/docs/Web/CSS/color_value
   * @defaultValue #000000
   */
  fgColor?: string;
  /**
   * Whether or not a margin of 4 modules should be rendered as a part of the
   * QR Code.
   * @deprecated Use `marginSize` instead.
   * @defaultValue false
   */
  includeMargin?: boolean;
  /**
   * The number of _modules_ to use for margin. The QR Code specification
   * requires `4`, however you can specify any number. Values will be turned to
   * integers with `Math.floor`. Overrides `includeMargin` when both are specified.
   * @defaultValue 0
   */
  marginSize?: number;
  /**
   * The title to assign to the QR Code. Used for accessibility reasons.
   */
  title?: string;
  /**
   * The minimum version used when encoding the QR Code. Valid values are 1-40
   * with higher values resulting in more complex QR Codes. The optimal
   * (lowest) version is determined for the `value` provided, using `minVersion`
   * as the lower bound.
   * @defaultValue 1
   */
  minVersion?: number;
  /**
   * If enabled, the Error Correction Level of the result may be higher than
   * the specified Error Correction Level option if it can be done without
   * increasing the version.
   * @defaultValue true
   */
  boostLevel?: boolean;
  /**
   * The settings for the embedded image.
   */
  imageSettings?: {
    /**
     * The URI of the embedded image.
     */
    src: string;
    /**
     * The height, in pixels, of the image.
     */
    height: number;
    /**
     * The width, in pixels, of the image.
     */
    width: number;
    /**
     * Whether or not to "excavate" the modules around the embedded image. This
     * means that any modules the embedded image overlaps will use the background
     * color.
     */
    excavate: boolean;
    /**
     * The horiztonal offset of the embedded image, starting from the top left corner.
     * Will center if not specified.
     */
    x?: number;
    /**
     * The vertical offset of the embedded image, starting from the top left corner.
     * Will center if not specified.
     */
    y?: number;
    /**
     * The opacity of the embedded image in the range of 0-1.
     * @defaultValue 1
     */
    opacity?: number;
    /**
     * The cross-origin value to use when loading the image. This is used to
     * ensure compatibility with CORS, particularly when extracting image data
     * from QRCodeCanvas.
     * Note: `undefined` is treated differently than the seemingly equivalent
     * empty string. This is intended to align with HTML behavior where omitting
     * the attribute behaves differently than the empty string.
     */
    crossOrigin?: 'anonymous' | 'use-credentials' | '' | undefined;
  };
};

value

The value to encode into the QR Code. See Encoding Mode for additional details.

TypeDefault Value
string | string[]—

size

The size, in pixels, to render the QR Code.

TypeDefault Value
number128

level

The Error Correction Level to use. Information is encoded in QR Codes such that they can lose part of their visible areas and still be decodable. The amount of correction depends on this value. Higher error correction will result in more complex QR Codes.

  • L = low (~7%)
  • M = medium (~15%)
  • Q = quartile (~25%)
  • H = high (~30%)

See Wikipedia or the official QR Code documentation for a more detailed explaination.

TypeDefault Value
L | M | Q | HL

bgColor

The background color used to render the QR Code. This is passed directly to the Canvas (ctx.fillStyle = bgColor) or the SVG <path> (fill={bgColor}), both which accept any CSS color.

TypeDefault Value
string#FFFFFF

fgColor

The foreground color used to render the QR Code. It follows the same constraints as bgColor

TypeDefault Value
string#000000

includeMargin

[!WARNING] This has been deprecated in v4 and will be removed in a future version. Use marginSize instead.

Whether or not a margin of 4 modules should be rendered as a part of the QR Code.

TypeDefault Value
booleanfalse

marginSize

The number of modules to use for margin. The QR Code specification requires 4, however you can specify any number. Values will be turned to integers with Math.floor. Overrides includeMargin when both are specified.

TypeDefault Value
number0

title

The title to assign to the QR Code. Used for accessibility reasons.

TypeDefault Value
string—

minVersion

The minimum version used when encoding the QR Code. Valid values are 1-40 with higher values resulting in more complex QR Codes. The optimal (lowest) version is determined for the value provided, using minVersion as the lower bound.

TypeDefault Value
number1

boostLevel

If enabled, the Error Correction Level of the result may be higher than the specified Error Correction Level option if it can be done without increasing the version.

TypeDefault Value
booleantrue

imageSettings

Used to specify the details for an embedded image, often used to embed a logo.

TypeDefault Value
object (see fields below)—

imageSettings.src

The URI of the embedded image. This will get passed directly to src of an img element for QRCodeCanvas or the href of an inline image for QRCodeSVG.

TypeDefault Value
string—

imageSettings.height

The height, in pixels, of the embedded image.

TypeDefault Value
number—

imageSettings.width

The width, in pixels, of the embedded image.

TypeDefault Value
number—

imageSettings.excavate

Whether or not to "excavate" the modules around the embedded image. This means that any modules the embedded image overlaps will use the background color. Use this to ensure clean edges around your image. It is also useful when embedding images with transparency.

TypeDefault Value
boolean—

imageSettings.x

The horizontal offset, in pixels, of the embedded image. Positioning follows standard DOM positioning, with top left corner being 0.

When not specified, will center the image.

TypeDefault Value
number—

imageSettings.y

The vertical offset, in pixels, of the embedded image. Positioning follows standard DOM positioning, with top left corner being 0.

When not specified, will center the image.

TypeDefault Value
number—

imageSettings.opacity

The opacity of the embedded image, in the range of 0 to 1.

TypeDefault Value
number1

imageSettings.crossOrigin

The cross-origin value to use when loading the embedded image. Note that undefined works as typically does with React, excluding the attribute from the DOM node. This is intended to align with HTML behavior where omitting the attribute behaves differently than the empty string.

TypeDefault Value
string—

Custom Styles

qrcode.react will pass through any additional props to the underlying DOM node (<svg> or <canvas>). This allows the use of inline style or custom className to customize the rendering. One common use would be to support a responsive layout.

[!NOTE] In order to render QR Codes in <canvas> on high density displays, we scale the canvas element to contain an appropriate number of pixels and then use inline styles to scale back down. We will merge any additional styles, with custom height and width overriding our own values. This allows scaling to percentages but if scaling beyond the size, you will encounter blurry images. I recommend detecting resizes with something like react-measure to detect and pass the appropriate size when rendering to <canvas>.

Encoding Mode

qrcode.react supports encoding text only. Prior to v4.1.0, this was done in a single segment. Since then, the value prop can be an array of strings. Each member will be encoded separately. The encoding library being used does minimal detection to determine if each segment being encoded can follow an optimized path for Numeric or Alphanumeric modes, allowing for more data to be encoded. Otherwise, it will encode following Byte mode. This mode includes supports multi-byte Unicode characters such as Kanji, however it does not support the optimized Kanji encoding mode.

LICENSE

qrcode.react is licensed under the ISC license.

qrcode.react bundles QR Code Generator, which is available under the MIT license.