qrcode.react vs qr.js vs react-qr-code vs qr-code-styling vs qrious
QR Code Generation Libraries
qrcode.reactqr.jsreact-qr-codeqr-code-stylingqriousSimilar Packages:
QR Code Generation Libraries

QR Code generation libraries in JavaScript provide developers with tools to create QR codes programmatically. These libraries offer various features such as customization, styling, and integration with web applications. They simplify the process of generating QR codes, which can be used for a variety of purposes including marketing, payments, and information sharing. The libraries range from simple, lightweight solutions to more feature-rich options that allow for extensive customization and styling.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
qrcode.react2,345,3344,214115 kB34a year agoISC
qr.js1,440,522---13 years agoMIT
react-qr-code1,093,64184813.8 kB135 months agoMIT
qr-code-styling229,2692,620516 kB1048 months agoMIT
qrious66,9321,619-439 years agoGPL-3.0
Feature Comparison: qrcode.react vs qr.js vs react-qr-code vs qr-code-styling vs qrious

Customization

  • qrcode.react:

    qrcode.react allows for customization through React props, including size, color, and error correction levels. It is ideal for React projects that need moderate customization.

  • qr.js:

    qr.js provides minimal customization, focusing on generating standard QR codes with basic styling. It is suitable for projects that do not require advanced design features.

  • react-qr-code:

    react-qr-code provides basic customization options like size and color, with a focus on simplicity. It is suitable for React applications that need straightforward QR code customization.

  • qr-code-styling:

    qr-code-styling offers extensive customization options, including the ability to style individual modules, add gradients, and incorporate images. It is the best choice for projects that require visually appealing QR codes with advanced design features.

  • qrious:

    qrious offers basic customization options such as setting the size, background color, and foreground color. It is a good choice for projects that need simple customization without complexity.

Integration

  • qrcode.react:

    qrcode.react is specifically designed for React applications, making it easy to integrate into React projects. It leverages React's component architecture for seamless integration.

  • qr.js:

    qr.js is a standalone library that can be easily integrated into any web project. Its lightweight nature makes it ideal for quick integration without adding significant overhead.

  • react-qr-code:

    react-qr-code is designed for React applications and provides a simple API for integration. It is optimized for React and leverages React's features for efficient rendering.

  • qr-code-styling:

    qr-code-styling can be integrated into any web application and supports both JavaScript and TypeScript. It is versatile and can be used in various frameworks and environments.

  • qrious:

    qrious is a standalone library that can be integrated into any web project. It is simple to use and does not have dependencies, making it easy to add to existing projects.

Performance

  • qrcode.react:

    qrcode.react performs well within React applications, but performance may vary depending on the complexity of the component and the level of customization.

  • qr.js:

    qr.js is highly performant and lightweight, making it ideal for applications that require fast QR code generation with minimal resource usage.

  • react-qr-code:

    react-qr-code is optimized for performance in React applications, providing fast rendering with minimal overhead. It is ideal for applications that need efficient QR code generation.

  • qr-code-styling:

    qr-code-styling is optimized for performance but may have a slight overhead due to its advanced styling features. It is suitable for applications where visual quality is important, but performance should still be considered.

  • qrious:

    qrious is lightweight and performs well for quick QR code generation. It is suitable for applications that need fast rendering without heavy resource consumption.

Ease of Use: Code Examples

  • qrcode.react:

    Example of qrcode.react in a React component:

    import React from 'react';
    import { QRCode } from 'qrcode.react';
    
    const MyQRCode = () => (
      <QRCode
        value="https://example.com"
        size={256}
        bgColor="#ffffff"
        fgColor="#000000"
        level="H"
        includeMargin={true}
      />
    );
    
    export default MyQRCode;
    
  • qr.js:

    Example of qr.js for basic QR code generation:

    import QRCode from 'qr.js';
    
    const qr = new QRCode('https://example.com');
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');
    const size = 256;
    canvas.width = size;
    canvas.height = size;
    
    const cellSize = size / qr.modules.length;
    ctx.fillStyle = '#000';
    qr.modules.forEach((row, y) => {
      row.forEach((cell, x) => {
        if (cell) {
          ctx.fillRect(x * cellSize, y * cellSize, cellSize, cellSize);
        }
      });
    });
    
    document.body.appendChild(canvas);
    
  • react-qr-code:

    Example of react-qr-code in a React component:

    import React from 'react';
    import QRCode from 'react-qr-code';
    
    const MyQRCode = () => (
      <QRCode
        value="https://example.com"
        size={256}
        fgColor="#000000"
        bgColor="#ffffff"
      />
    );
    
    export default MyQRCode;
    
  • qr-code-styling:

    Example of qr-code-styling with advanced customization:

    import QRCodeStyling from 'qr-code-styling';
    
    const qrCode = new QRCodeStyling({
      width: 300,
      height: 300,
      data: 'https://example.com',
      image: 'https://example.com/logo.png',
      dotsOptions: {
        color: '#4267b2',
        type: 'rounded',
      },
      backgroundOptions: {
        color: '#e9ebee',
      },
      imageOptions: {
        crossOrigin: 'anonymous',
        margin: 20,
      },
    });
    
    qrCode.append(document.getElementById('qr-code'));
    
  • qrious:

    Example of qrious for simple QR code generation:

    import { QRious } from 'qrious';
    
    const qr = new QRious({
      element: document.getElementById('qr'),
      value: 'https://example.com',
      size: 256,
      background: '#ffffff',
      foreground: '#000000',
    });
    
How to Choose: qrcode.react vs qr.js vs react-qr-code vs qr-code-styling vs qrious
  • qrcode.react:

    Choose qrcode.react if you are working with React and need a component-based solution for generating QR codes. It integrates seamlessly with React applications and allows for easy customization through props.

  • qr.js:

    Choose qr.js if you need a lightweight and simple solution for generating QR codes with minimal dependencies. It is suitable for projects that require basic QR code functionality without additional features.

  • react-qr-code:

    Choose react-qr-code if you need a React component for generating QR codes with a focus on simplicity and performance. It is designed for React applications and offers a clean API for quick integration.

  • qr-code-styling:

    Choose qr-code-styling if you need highly customizable QR codes with advanced styling options, including gradients, images, and more. It is ideal for projects where the visual appearance of the QR code is important.

  • qrious:

    Choose qrious if you need a simple and easy-to-use library for generating QR codes with support for basic customization. It is lightweight and provides a straightforward API for quick QR code generation.

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.