React library

Basic usage

Which qrdx component to render, and the props that set a code's size, quiet zone, colors, shapes, logo, frame and error correction.

QRCode is the component to reach for: it takes every styling option and a simple logo prop, and it renders on the server. This page goes through the props you set most often. For every prop, see the library API reference.

Choose a component

ComponentWhat it drawsUse it when
QRCodeAn <svg> with every style option, plus logo, logoOptions, hideLogo and scale. Takes no other attributesAlmost always
QRCodeSVGThe same <svg>, with the logo given as raw imageSettings in pixels. Any other prop (aria-label, className, role) goes on the <svg>You need attributes on the <svg>, you lay the logo out yourself, or you port code from another renderer
QRCodeCanvasA <canvas> with plain square modules and solid colorsYou need a canvas element. Patterns, eye colors, gradients and templates are ignored

QRCode and QRCodeSVG use no browser-only hooks, so they render in React Server Components and in static HTML. QRCodeCanvas ships with "use client".

components/menu-code.tsx
import { QRCode } from "qrdx";

export function MenuCode() {
  return (
    <div role="img" aria-label="QR code for the menu">
      <QRCode value="https://example.com/menu" size={256} margin={4} />
    </div>
  );
}

value is encoded exactly as you pass it, so a Wi-Fi payload, a vCard, mailto: or plain text all work. QRCode takes the code's own props and style, nothing else: give it an accessible name by wrapping it, as above. QRCodeSVG puts aria-label, className, role and any other attribute on the <svg> itself.

Size and quiet zone

  • size is the width and height in pixels (default 128). Below about 128 px a dense code gets hard to scan from a screen.
  • margin is the quiet zone around the code, in modules (default 0). The QR standard asks for 4. Set it when the code sits on a photo, a pattern or a dark page; a code inside a white card with its own padding can keep 0.
  • scale multiplies size on QRCode.

A frame or a template changes the output size. See Frame or template.

Colors

components/brand-code.tsx
import { QRCode } from "qrdx";

export function BrandCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      fgColor="#1d4ed8"
      bgColor="#f8fafc"
      eyeColor="#0f172a"
      dotColor="#1d4ed8"
    />
  );
}
  • fgColor colors the data modules, bgColor the background, eyeColor the three corner eyes and dotColor the dot inside each eye. The eye colors default to fgColor.
  • Each takes any CSS color (#1d4ed8, rgb(29 78 216), a named color), or a gradient object. Set colors and gradients covers gradients, see-through colors and image fills.
  • Keep the modules darker than the background. Scanners read dark on light; a light code on a dark background works in most phone cameras but not in some older apps.

Shapes

components/rounded-code.tsx
import { QRCode } from "qrdx";

export function RoundedCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      bodyPattern="rounded"
      cornerEyePattern="extra-rounded"
      cornerEyeDotPattern="rounded"
    />
  );
}
  • bodyPattern shapes the data modules (default circle). There are 23 to choose from.
  • cornerEyePattern shapes the three corner eyes (default gear), one of 17.
  • cornerEyeDotPattern shapes the dot inside each eye (default circle), one of 21.

Shapes, eyes and frames draws every value live. Choose module and eye shapes explains module scale, shaped codes and the few pairs that scan badly together.

components/logo-code.tsx
import { QRCode } from "qrdx";

export function LogoCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      level="H"
      logo="/logo.png"
      logoOptions={{ size: 0.2, padding: 1 }}
    />
  );
}

logo takes a path in your app, a URL or a data URL. The modules behind it are cleared, so the code relies on error correction to scan: use level="H". logoOptions sets the logo's width as a share of the code (0.1 to 0.3, default 0.25), its clear space in modules, its position and its crop. The component never draws a logo bigger than the code can repair. Add a logo in code has the details.

Frame or template

components/framed-code.tsx
import { QRCode } from "qrdx";

export function FramedCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      frame={{ style: "banner-bottom", text: "Scan me", color: "#0f172a" }}
    />
  );
}
  • frame draws a call-to-action frame around the code. The code stays size wide and the output grows to fit the frame. There are 19 built-in styles, plus the official frame library and your own frame specs. See Frames, scan score and print files.
  • templateId draws a template such as Arrow or StandardBox instead. A template draws its whole artwork at size, with the code smaller inside it. See Use a frame template.

With both set, the frame is drawn around the template's artwork.

Error correction

levelCan be damagedUse it for
Labout 7%Clean screens, short links, the smallest code
Mabout 15%Long payloads such as vCards, where a smaller code matters more
Qabout 25%The default. General use
Habout 30%Logos, art, print that gets scratched or folded

A higher level adds modules, so the code gets denser at the same size. autoLevel raises the level to H on its own when a logo covers more than 7% of the code; it is off by default so existing codes keep their look.

Was this page helpful?

Last updated on

On this page