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. Any other prop (aria-label, className, role) goes on the <svg>Almost always
QRCodeSVGThe same <svg>, with the logo given as raw imageSettings in pixels. Any other prop goes on the <svg> tooYou 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 and gradients 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. The wrapper gives the code an accessible name. From qrdx 0.0.56, QRCode also puts aria-label, className, role and any other attribute on the <svg> itself, as QRCodeSVG always has, so you can label the code without a wrapper. Older versions of QRCode drop those props.

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). Set 2 or more when the code sits on a photo, a pattern or a dark page, where a code with no light border may not scan (the QR standard asks for 4); a code inside a white card with its own padding can keep 0.
  • scale multiplies size on QRCode.

A frame changes the output size. See Frame.

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 25 to choose from.
  • cornerEyePattern shapes the three corner eyes (default gear), one of 22.
  • cornerEyeDotPattern shapes the dot inside each eye (default circle), one of 22.

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

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 25 built-in styles, from banners and bubbles to artwork such as arrow and dot-ring, plus the official frame library and your own frame specs. See Frames, scan score and print files.

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

The percentages are shares of the code's codewords, not of its area, so a logo can't cover 30% of a level H code: our scan study measured the largest logo each level holds. 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.

The level is a minimum: when the data still fits the same version at a higher level, the encoder uses the higher one, which costs nothing in size. exactLevel turns that off, so the code is encoded at exactly the level it is drawn at. A Swiss QR-bill needs this: SIX's guidelines ask for error correction M (Swiss Implementation Guidelines for the QR-bill, section 6.1), and QRdx's editor, API and MCP server set exactLevel for every Swiss QR-bill payload.

components/bill-code.tsx
<QRCode value={swissQrBillPayload} level="M" exactLevel />

Was this page helpful?

Last updated on

On this page